【问题标题】:jquery dynamically changed property of the checkbox but not getting each checkbox valuejquery 动态更改了复选框的属性,但没有获取每个复选框的值
【发布时间】:2018-09-10 05:33:59
【问题描述】:

这是我尝试做的。我只是在检查 1 项时检查了所有项目。但是当检查所有项目时,未找到已检查的属性。不明白做错了什么。

    <html>
    <td>
    <label>
    <input type="checkbox" rel="{{ $sq->id }}" class="select-multiple {{$qr- 
    >item_no}} select-items{{$j}}" value="{{$qr->item_no}}" name="state{{ 
    $sq->id }}">
    </label>
    </td>
    </html>


    var itemCode ='';
    $('.select-multiple').on('click',function (ev) {
    ev.preventDefault();
    itemCode = $(this).val();
    if(!$(this).is(':checked')){
        $('.'+itemCode).prop('checked', false);
    }else{
        $('.'+itemCode).prop('checked', true);
        $("input:checkbox[class="+itemCode+"]:checked").each(function() {
            alert(itemCode);
        });
    }
  });

【问题讨论】:

  • 1.在脚本代码之前添加jquery库。2.将代码包装在&lt;script&gt;&lt;/script&gt;
  • 只是不能给出完整的代码。当然我已经做到了。这不是问题。
  • 在您提供相关代码(HTML+jquery)之前,您的问题代码是无用的。我们无法检查。
  • 如果没有足够的信息但@B,我很抱歉。 Desai 的回答对我有用。

标签: php jquery html laravel-5 checkbox


【解决方案1】:

您的类选择器 for 循环不正确。改变

$("input:checkbox[class="+itemCode+"]:checked").each(function() {
            alert(itemCode);
        });

$("."+itemCode+":checkbox:checked").each(function() {
            alert(itemCode);
        });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-08
    • 2013-02-23
    • 1970-01-01
    • 2014-06-16
    • 2014-08-06
    • 2012-06-07
    相关资源
    最近更新 更多