2013-02-04 77 views
0

我有一个CheckBoxesGridView,现在我想检查是否CheckBoxchecked或不。ChekBox检查总是返回false

<asp:CheckBox ID="cbIsReceived" runat="server" AutoPostBack="true" Checked='<%# Eval("IsReceived") %>' OnCheckedChanged="cbIsReceived_CheckedChanged" cssClass="cbIsReceived"/> 

我正在使用以下jquery查看CheckBox状态。

$('.cbIsReceived').live('click', function() { 

     var result = $(this).is(':checked'); 
     alert(result); 
    }); 

这总是提醒虚假。即使我检查它。

请帮忙。

+0

最新版本的'VAR结果,尝试= $(本).prop( '检查')'? (顺便说一句,现已弃用) – nicolast

+0

我可以看到http://jsfiddle.net/eSmAU/这工作正常 – HADI

+0

雅我测试它在jsfiddle。它的工作finr。但它现在在我的页面上工作。我不知道什么,我已经尝试过AutoPostback也是 –

回答

1
$('#<%= cbIsReceived.ClientID%>').on('click', function() { 
    var result = $(this).is(':checked'); 
    alert(result); 
}); 

$('.cbIsReceived').on('click', function() { 
    var result = $(this).is(':checked'); 
    alert(result); 
}); 

使用on()的弃用live()

0

使用'更改'而不是'点击'。

$('.cbIsReceived').live('change', function() { 

    var result = $(this).is(':checked'); 
    alert(result); 
}); 
+0

我试过这个。相同的结果 –

0

试试这个代码:

$('.cbIsReceived').live('click', function() { 
    if((this).is(':checked')){ 
     alert(result); 
    } 
}); 
+0

如果多个类别为.cbIsReceived的checkibox会怎样?编辑:好吧,这样。 – nicolast

1

使用prop功能intseadhttp://api.jquery.com/prop/

$(this).prop('checked');

而且live不是作品的jquery 1.9http://api.jquery.com/live/