![](/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.