jQuery fire复选框单击值

时间:2014-03-24 11:46:48

标签: jquery

我需要按值点击一个复选框来打开一个对话框......有人可以解释为什么这不起作用吗?

形式:

<span class="wpcf7-form-control-wrap obj">
    <span class="wpcf7-form-control wpcf7-checkbox wpcf7-validates-as-required wpcf7-exclusive-checkbox">
        <span class="wpcf7-list-item first">
            <label>
                <input type="checkbox" name="obj" value="Value 1" />
                <span class="wpcf7-list-item-label">Value 1</span>
            </label>
        </span>
        <span class="wpcf7-list-item">
            <label>
                <input type="checkbox" name="obj" value="Value 2" />
                <span class="wpcf7-list-item-label">Value 2</span>
            </label>
        </span>
        <span class="wpcf7-list-item last">
            <label>
                <input type="checkbox" name="obj" value="Other" />
                <span class="wpcf7-list-item-label">Other</span>
            </label>
        </span>
    </span>
</span>

脚本:

jQuery(document).ready(function($){
    $("input[type=checkbox][value='Value 1']").on('click',function() {
        alert('abcd');
    });
});

1 个答案:

答案 0 :(得分:0)

看起来你需要委托事件,例如:

$(document).on('click', "input[type=checkbox][value='Value 1']", function() {
        alert('abcd');
    });

请阅读:https://learn.jquery.com/events/event-delegation/

相关问题