打开一个按钮的HTML选择列表中单击
我创建了一个选项列表在网页上,我想用一个<div>
创建一个按钮打开选择列表时,从列表中选择一个选项,然后选择的值来对div也。打开一个按钮的HTML选择列表中单击
所以在这里我想的JavaScript属性,打开按钮,单击列表中这样
document.getElementById('selectedlist').open.
任何身体的东西对此有何建议?
看看http://code.google.com/p/expandselect/。我认为这是你想要的。 然后你可以像这样打开选择。
ExpandSelect("myselect_id")
看怎么将在移动浏览器正常工作(客户的43%),而许多或所有的移动webkit版本都可以完成用户最初想要的功能,只需关注选择即可。 – 2012-04-26 06:48:35
它没有工作,你知道它将如何工作? – 2012-04-26 06:54:49
@HarishKumar你能展示你的代码吗?将“ExpandSelect.js”包含到您的页面中后,您可以打开按钮单击时的选择。 '' – 2012-04-26 07:11:28
这里是简单的Javascript代码来打开(切换)单击按钮上的选择框。
<script type="text/javascript">
function expandSelect(id){
var select_flag = document.getElementById('select_flag').value;
if(select_flag==1){
var select_box = document.getElementById(id);
select_box.size = 1;
document.getElementById('select_flag').value = 0;
}else{
var select_box = document.getElementById(id);
select_box.size = select_box.options.length;
document.getElementById('select_flag').value = 1;
}
}
</script>
<button onclick="expandSelect('select_box')"> Toggle Select Box </button>
<div id="container">
<select name="select_box" id="select_box" >
<option value="">Select</option>
<option value="">option1</option>
<option value="">option2</option>
<option value="">option3</option>
<option value="">option4</option>
<option value="">option5</option>
<option value="">option6</option>
</select>
<input type="hidden" name="select_flag" id="select_flag" value="0">
</div>
在这里,我们可以检查[DEMO](http://jsfiddle.net/gchoken/yqfEF/1/)kriangkrai答案 – Gowri 2012-08-13 14:28:39