0

我使用 javascript 制作了一个组合框,该组合框从 html 文件本身获取值,下面是组合框的代码:

   <!DOCTYPE html>
   <html lang="en">
   <head>
   <meta charset="utf-8">
   <title>pro-v0</title>
   <style type="text/css" media="screen">
div.combobox    {font-family: Tahoma;font-size: 12px}
div.combobox    {position: relative;zoom: 1}
div.combobox    div.dropdownlist    {display: none;width: 200px;
    border: solid 1px #000;background-color: #fff;
    height: 200px;overflow: auto;position: absolute;
    top: 18px;left: 0px;}
div.combobox    .dropdownlist   a   {display: block;text-decoration: none;
    color: #000;padding: 1px;height: 1em;cursor: default}
div.combobox    .dropdownlist   a.light {color: #fff;
    background-color: #007}
div.combobox    .dropdownlist, input {font-family: Tahoma;font-size: 12px;}
div.combobox    input {float: left;width: 182px;
    border: solid 1px #ccc;height: 15px}
div.combobox    span    {border: solid 1px #ccc;background: #eee;
    width: 16px;height: 17px;
    float: left;text-align: center;border-left: none;cursor: default}
  </style>
  </head>

  <body>
  <div class="combobox">
<input type="text" name="comboboxfieldname" id="cb_identifier">

<span>V</span>
<div class="dropdownlist">
    <a>option 1</a>
    <a>option 2</a>
    <a>option 3</a>
            <a>option 4</a>
</div>
    </div>
    <script type="text/javascript" charset="utf-8"    src="https://raw.github.com/RUPOJS/jsCombo/master/combobox.js"></script>
    <script type="text/javascript" charset="utf-8">
    var no = new inputSelect('cb_identifier');
    </script>
    </body>
    </html>

现在,如何从 javascript 文件或其他文件中获取值或如何创建

使用 javascript 包含所有值的下拉列表 div。提前致谢。

4

1 回答 1

0

试试这个

...
above same  as your code 

<script type="text/javascript" charset="utf-8"    src="https://raw.github.com/RUPOJS/jsCombo/master/combobox.js"></script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" charset="utf-8">
    var no;
    $(document).ready(function(){
      var list = "<a>option 4</a><a>option 4</a><a>option 5</a><a>option 6</a>"
     $(".dropdownlist").append(list).each(function() {
         no = new inputSelect('cb_identifier');
       });
    });

</script>
</body>
</html>

在纯 java 脚本中

尝试使用这个

<script type="text/javascript" charset="utf-8"    src="https://raw.github.com/RUPOJS/jsCombo/master/combobox.js"></script>
<script type="text/javascript" charset="utf-8">
    var string = "<a>option 5</a><a>option 6</a><a>option 7</a><a>option 8</a>";
    var getElement = document.getElementsByClassName("dropdownlist")[0];
    getElement.innerHTML = getElement.innerHTML+string;
    var no = new inputSelect('cb_identifier');

</script>
</body>
</html>

使用这个循环

<script type="text/javascript" charset="utf-8">
     var strArray = [["option 1"], ["option 2"], ["option 3"], ["option 4"], ["option 4"]]; 
     var string = ""
     for(i=0; i < strArray.length; i++)
     {
        string +="<a>"+strArray[i][0]+"</a>";
     }
     var getElement = document.getElementsByClassName("dropdownlist")[0];
     getElement.innerHTML = getElement.innerHTML+string;
     var no = new inputSelect('cb_identifier');
</script>
于 2013-06-20T09:22:27.060 回答