如何使用 jQuery 检测 Joomla 中的选择框更改

How to detect selectbox change in Joomla with jQuery

我需要检测 select 框(Joomla 表单字段 - 列表)的变化,但 Joomla 经典 html select 更改为 Joomla 样式并且 html 命令被隐藏。当我更改 select 框中的项目时 jQuery 未检测到此更改。

    <div class="controls">
        <select aria-required="true" required="required" size="40" class="required chzn-done" name="jform[id_voucher_type]" id="jform_id_voucher_type" style="display: none;">
            <option value="1">Jednorázový</option>
            <option value="2">Opakovatelný</option>
        </select>
        <div class="chzn-container chzn-container-single chzn-container-single-nosearch" style="width: 220px;" title="" id="jform_id_voucher_type_chzn">
            <a tabindex="-1" class="chzn-single"><span>Opakovatelný</span><div><b></b></div></a>
            <div class="chzn-drop"><div class="chzn-search"><input type="text" autocomplete="off" readonly=""></div>
            <ul class="chzn-results">
                <li data-option-array-index="0" style="" class="active-result">Jednorázový</li>
                <li data-option-array-index="1" style="" class="active-result result-selected">Opakovatelný</li>
            </ul>
        </div>
    </div>

我尝试了一些设置侦听器的方法,但没有任何效果。

    jQuery("#form_id_voucher_type").change(function() {
        alert("yeah");
    })

有什么方法可以检测用户是否更改了 selectbox 项目?

谢谢

Id 选择器不正确,是 jform_id_voucher_type 还是 form_id_voucher_type 而没有 j,试试这个:

jQuery(".controls").on("change", "#jform_id_voucher_type", function() {
    alert("yeah");
});