Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击按钮打开html选定列表_Javascript_Html - Fatal编程技术网

Javascript 单击按钮打开html选定列表

Javascript 单击按钮打开html选定列表,javascript,html,Javascript,Html,我在一个网页中创建了一个选项列表,我想用一个按钮打开选择列表,该按钮是用创建的。当从列表中选择一个选项时,所选值也会出现在div上 因此,我希望javascript属性在单击按钮时打开列表,如下所示 document.getElementById('selectedlist').open. 有人对此有什么建议吗?看看。我想这就是你想要的。 然后你可以像这样打开选择按钮 ExpandSelect("myselect_id") 下面是单击按钮打开(切换)选择框的简单Javascript代码 &l

我在一个网页中创建了一个选项列表,我想用一个按钮打开选择列表,该按钮是用
创建的。当从列表中选择一个选项时,所选值也会出现在div上

因此,我希望javascript属性在单击按钮时打开列表,如下所示

document.getElementById('selectedlist').open.
有人对此有什么建议吗?

看看。我想这就是你想要的。 然后你可以像这样打开选择按钮

ExpandSelect("myselect_id")

下面是单击按钮打开(切换)选择框的简单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>

功能选择(id){
var select_flag=document.getElementById('select_flag')。值;
如果(选择_标志==1){
var select_box=document.getElementById(id);
选择_box.size=1;
document.getElementById('select_flag')。值=0;
}否则{
var select_box=document.getElementById(id);
选择_box.size=选择_box.options.length;
document.getElementById('select_flag')。值=1;
}
}
切换选择框
挑选
选择1
选择2
选择3
选择4
选择5
选择6

看看这在移动浏览器(43%的客户端)中是如何工作的,而许多或所有的移动webkit版本只需关注选择即可满足用户最初的需求。@HarishKumar您能展示您的代码吗?将
ExpandSelect.js
包含到页面中后,您可以像这样单击按钮时打开选择<代码>这里是我的代码,我用过所有的商店&Darr;category是选择列表的id。@Kriangkrai Bumroungruksa哦,是的,很抱歉,它工作了,我当时更改了id。谢谢lot@HarishKumar不客气。如果您认为此方法解决了您的问题,请按复选标记将其标记为已接受答案。你也可以考虑接受你的其他问题。在这里我们可以检查Kiangkrayi的答案。