【问题标题】:getting wrong value checkbox jQuery获取错误的值复选框jQuery
【发布时间】:2020-01-26 16:04:58
【问题描述】:

当我在控制台中选择值为10000 的复选框时,有两个复选框并且都具有不同的值,我总是得到值1000

HTML

<input type="checkbox" name="group2[]" class="ci_check" value="1000" />1000
<input type="checkbox" name="group2[]" class="ci_check" value="10000" />10000

jQuery

$(".ci_check").click(function(){
    if ($('.ci_check').is(":checked")) {
        var abc = $("input[type='checkbox']").val();
        console.log(abc);
    }
});

【问题讨论】:

    标签: jquery


    【解决方案1】:

    因为您没有选择点击的元素。试试这个:

    $(".ci_check").click(function(){
        if ($(this).is(":checked")) {
            var abc = $(this).val();
            console.log(abc);
        }
    });
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-19
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 2012-07-02
    • 2015-10-30
    相关资源
    最近更新 更多