简体   繁体   English

复选框未完成补全功能html javascript

[英]Checkbox not completing completing function html javascript

I have multiple check boxes in my webpage. 我的网页中有多个复选框。 Each checkbox runs a javascript function called "adds". 每个复选框都会运行一个名为“ adds”的javascript函数。 This works when you click the box manually. 当您手动单击该框时,此方法有效。

I have another type of checkbox which checks all the check boxes in that div, but when this is checked it does not run the function "adds" on the checkboxes it checks. 我有另一种类型的复选框,它选中了该div中的所有复选框,但是当选中该复选框时,它不会在它选中的复选框上运行“添加”功能。

Does anyone know why? 有人知道为什么吗?

Check all in div function: 在div中检查所有功能:

<script type="text/javascript" language="javascript">
function checkCheckboxes( id, pID ){
$('#'+pID).find(':checkbox').each(function(){
jQuery(this).prop('checked', $('#' + id).is(':checked'));
});  
}
</script>

Adds Function: 增加功能:

<script type="text/javascript" language="javascript">
function adds(id) {

var value = $(id).val()

    jQuery.ajax({
        url: "selection_update.php",
        data: {"value": value},
        type: "POST",
        dataType: 'json',
            success:function(responce){
            $("#check").html(responce);
        }
    });
}
</script>

I call the adds function through this: 我通过以下方式调用adds函数:

<input class="mycheckbox" type="checkbox" value="$table3[Test_ID]" onchange="adds('#tccb$j')" id="tccb$j" unchecked>

and call the checkall function through: 并通过以下方式调用checkall函数:

<input class="mycheckbox" type="checkbox" onclick="checkCheckboxes(this.id, 'collapse$count');" id="mcb$count" unchecked/>

Simply changing the 'checked' property will not trigger the event. 只需更改“选中”属性将不会触发该事件。 You need to use .trigger( "change" ) or .change() as well. 您还需要使用.trigger( "change" ).change()

Your key line will look like this... 您的关键行将如下所示...

jQuery(this).prop('checked', $('#' + id).is(':checked')).change();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM