开发者

how to create drop down list in java script?

For example if i have a list item like all,a,b,c,d. if i click all means it should not allow to choose o开发者_如何学Cther items, if i am not choosing all means it should allow to choose mulitle item from list


<script type="text/javascript">
  var creatLimit = 5;
  var fCount = 0;
  function addFileElement()
  {
      if(fCount < creatLimit)
      {
        var fObject = document.getElementById("name");
        var addButton = document.createElement("select");
        addButton.type = "select";
        addButton.name = "List["+fCount+"]";
        addButton.setAttribute("class", "normal");
        addButton.style.width = "250px";
        addButton.onkeydown = function(){
            blur();
        };
        var o2 = document.createElement("br");
        var o3 = document.createElement("br");
        fObject.appendChild(addButton);
        fObject.appendChild(o2);
        fObject.appendChild(o3);
        fCount++;
      }
  }
</script>


You are confusing your terminologies here slightly - JavaScript itself doesn't show any UI, it is the HTML (or the XUL or something completely different) which shows the UI.

Assuming that you are talking about html, the way to create a drop down list is simply to write the corresponding html for the drop down list to wherever it is in the document that you wish the drop down list to be placed, for example:

<div id="myDiv"></div>
<script type="text/javascript">
    myDiv = document.getElementById("myDiv");
    myDiv.innerHtml = "<select><option>a</option><option>b</option><option>c</option><option>d</option>";
</script>

Most likely you will be dynamically writing the HTML based on an existing list of items, but I don't want to go into that in too much detail because that will completely depend on your specific requirements and because jQuery will make this a lot easier.

EDIT: Typo fix in variable names.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜