[英]How to make <option>s of <select> show or hide using JavaScript?
我想通过程序(JS)进行<选择>显示或隐藏的选项,可以吗?
就像StackOverFlow首页中有趣的标签一样,当您键入一些单词时,下拉列表将展开并提供建议。
ps。我知道在这种情况下StackOverFlow没有使用select,无论如何都以它为例。
您可以从select
的options
集合中添加或删除项目。
这是一个删除一个项目并添加另一个项目的示例:
<html>
<head>
<title></title>
<script type="text/javascript">
function init() {
// get a reference to the element
var sel = document.getElementById('sel');
// remove an option
sel.options[2] = null;
// create a new option and add to the select
var opt = document.createElement('option');
opt.value = '5';
opt.text = 'five';
sel.options.add(opt);
}
</script>
</head>
<body onload="init();">
<form>
<select id="sel">
<option value="0">zero</option>
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
<option value="4">four</option>
</select>
</form>
</body>
</html>
function getCatListdef(sel)
{
var index = ajax.length;
ajax[index] = new sack();
ajax[index].requestFile = 'data.php?cat_code='+sel;
ajax[index].onCompletion = function(){ createCities(index) };
ajax[index].runAJAX();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.