如何在我的li列表中附加色块?

我有一个列表,在JavaScript中显示了一个附加数组,问题是我不知道如何从第一个测试色块中取出我的色块并将其附加到所有 <rewrite> <globalRules> <rule name="123" stopProcessing="false"> <match url=".*" /> <action type="Rewrite" url="http://work-monitoring/{R:0}" /> <conditions> <add input="{HTTP_HOST}" pattern="work-reports.mydomain.com" /> </conditions> </rule> </globalRules> </rewrite> <proxy enabled="false" /> 上。

我该如何解决这个问题?

这是我到目前为止所拥有的:

HTML:

<li>

JS:

SELECT A COLOR

    <div class="dropdown-container">
      <ul class="swatches" id="swatches">
        <li class="cell">
          COLOR 1
          <div class="colorBox"></div>
          <!--END COLOR BOX-->
        </li>
        <!--END LI-->
      </ul>
      <!--END SWATCHES-->
    </div>
    <!--END DROPDOWN CONTAINER-->

CSS:

//Establish the text array
  var colors = ["red","blue","green","purple","orange","teal","yellow"];

  //loop for text name
  for (var i = 0; i < colors.length; i++) {
    //set color for each
    var name = colors[i];
    //grab the ul- swatches
    var ul = document.getElementById("swatches");
    //creates the new li
    var li = document.createElement('li');
    //appending the array to the li
    li.appendChild(document.createTextNode(name));
    const div = document.createElement('div');
    div.classname = 'colorBox';
    li.appendChild(div);
    //appending the li to the ul 
    ul.appendChild(li);
  }

然后,我有了我的jsfiddle文件,该文件可以正常工作,但有色块。 有什么想法吗?

https://jsfiddle.net/kotten03/xwt708Lb/228/

dwzjr 回答:如何在我的li列表中附加色块?

您可以尝试以下内容。基本上,将div类的colorBox添加到每个列表项。

  //Establish the text array
  var colors = ["red","blue","green","purple","orange","teal","yellow"];


  //loop for text name
  for (var i = 0; i < colors.length; i++) {
    //set color for each
    var name = colors[i];
    //grab the ul- swatches
    var ul = document.getElementById("swatches");

    //creates the new li
    var li = document.createElement('li');
    //appending the array to the li
    li.appendChild(document.createTextNode(name));
    const div = document.createElement('div');
    div.className = 'colorBox'
    li.appendChild(div);

    //appending the li to the ul 
    ul.appendChild(li);
  }
本文链接:https://www.f2er.com/3165143.html

大家都在问