[英]Open a dropdown menu, clicking somewhere else on the page
I want to open this dropdown select, not by clicking on it's position but on another <span>
. 我要打开此下拉选择,而不是通过单击其位置,而是单击另一个<span>
。
Here is the dropdown menu: 这是下拉菜单:
<div class="styled-select">
<span id="camDurationSpanId" style="font-size:18px; position: absolute; top:8px; width:305px; height :42px;"></span>
<select id="camDurationId" name="camDuration" style="margin:42px 0 0 5px; border: none" onmousedown="{this.size=this.options.length;} " onchange='this.size=0;' onblur="this.size=0;">
<option value="0">All Duration</option>
<option value="1">Last Month</option>
<option value="2">Last Two Weeks</option>
<option value="3">Last Week</option>
<option value="4">Custom</option>
</select>
</div>
I want to open the dropdown menu by clicking over <span id="camDurationSpanId">
and also, I want to put the selected option into this span. 我想通过单击<span id="camDurationSpanId">
来打开下拉菜单,而且,我想将选定的选项放入该范围。
Here is my javascript: 这是我的JavaScript:
$(function() {
$('#camDurationSpanId').click(function() {
$('#camDurationId'). //don't know what to write here
});
});
is it possible to do so? 有可能这样做吗?
try 尝试
$(function () {
$('#camDurationSpanId').click(function () {
$('#camDurationId').attr('size',5);
});
});
example: https://jsfiddle.net/cmedina/o7zn8f8h/ 例如: https : //jsfiddle.net/cmedina/o7zn8f8h/
In order to programatically open a select
box you need to trigger a mousedown
event: 为了以编程方式打开select
框,您需要触发mousedown
事件:
$('#camDurationId').trigger('mousedown');
Here's a demo . 这是一个演示 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.