簡體   English   中英

觸發 <select>單擊另一個元素的onClick

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM