我使用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。 提前谢谢。
答案 0 :(得分: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>