![](/img/trans.png)
[英]How to trigger another function when i click on element with onclick atribute
[英]Trigger <select> click onClick of another element
我想在单击<select>
的父.select
类时打开它。
https://jsfiddle.net/6o31gfwa/-如果单击橙色块,您将看到选择已打开,但是单击选项不会关闭选择。 我该如何解决?
<label class="select">
<select>
<option>Body Fat</option>
<option>Height</option>
<option>Jean Size</option>
<option>Chest</option>
<optio>Pulse</option>
</select>
</label>
$('body')
.on('click', '.select', function(event) {
event.preventDefault();
var i = $('.select').index($(this)),
e = document.createEvent('MouseEvents');
e.initMouseEvent('mousedown');
$('select')[i].dispatchEvent(e);
});
是的,对。 先前的答案将不起作用。 您可以尝试以下方法:
$('select.class-of-select').val(the_same_select_val).change();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.