复选框更改后jQuery函数不执行

时间:2015-12-08 20:23:13

标签: javascript jquery checkbox

以下是我正在处理的代码:

$(document).ready(function(){
    var rewrite= function() {
        $("#numback_**SQL_Value**").attr("readonly" , "readonly");
        $("#numback_**SQL_Value**").attr("value" ,function() { return ($(".Report_Box").size() +**SQL_Value**;)}
    )};
    $(".Report_Box").click(rewrite);
});

Report_Box是代码中稍后的一类复选框。当其中一个复选框被更改时,应该触发重写功能。

重写应该锁定numback输入框,将其设置为只读,因为我将值设置为Report_Box点击的数量。

2 个答案:

答案 0 :(得分:0)

我简化了你的代码 - 它运作正常。我添加了可用于输入只读的代码... 请参阅此处使用prop not attr的说明: Setting a control to readonly using jquery 1.6 .prop()

<div>
<input type="checkbox" class="Report_Box"/>
<input type="checkbox" class="Report_Box"/>
<input type="checkbox" class="Report_Box"/>
<input type="checkbox" class="Report_Box"/>
<input type="checkbox" class="Report_Box"/>

<input type="text" id="makero"/>

<script>
$(document).ready(function(){

    var rewrite= function() {
        $('#makero').val($(".Report_Box").size()).prop('readonly', true);
            console.log($(".Report_Box").size());
        };
    $(".Report_Box").click(rewrite);
});

答案 1 :(得分:0)

这可能是导致你麻烦的错别字吗?试试这个:

$("#numback_**SQL_Value**").attr("value", function() { return($(".Report_Box").size()+"**SQL_Value**");} )};