English 中文(简体)
检查了 J查询检查复选框
原标题:JQuery Check for Checkbox is checked

函数总是返回错误, 即使复选框已经检查过, 也总是返回错误 。 我真的无法解开我做错了什么 。 我使用复选框来启用和禁用网格视图中的文本框。 但是, 它似乎不起作用 。 感谢您的帮助。 我在下面张贴了 html 和 jq 代码 。

HTML 代码 :

<asp:GridView ID="grdFees" runat="server" AllowPaging="false" CssClass="Grid" AutoGenerateColumns="false" EmptyDataText="No Data Found" EmptyDataRowStyle-HorizontalAlign="Center" EmptyDataRowStyle-CssClass="gridItem" TabIndex="5">
<Columns>
<asp:TemplateField HeaderText="Select" HeaderStyle-HorizontalAlign="center"
                                ItemStyle-HorizontalAlign="center" ItemStyle-Width="2%">
                                <ItemTemplate>
                                    <asp:CheckBox ID="chkselect" runat="server" CssClass="checkbox" 
                                    Width="15px" Checked="false" />
                                </ItemTemplate>
                            </asp:TemplateField>

</Columns>
</asp:GridView>

Jquery 代码 :

$(document).ready(function() 
    {
        $(".checkbox").click(function()
        {
        if ($(this).is(":checked")) 
        {
            alert("true");
        }else
        {
            alert("false");
        }
});
最佳回答

ASP.NET 可能不会将 CsClass 的值应用到复选框本身,而是应用到生成的标签和/或容器元素。

尝试使用 < a href=> "http://api.jquery.com/ checkbox-selector/" rel=" noreferrer" : checkbox 选择器

$(document).ready(function() {
    $("input:checkbox").click(function() {
        if ($(this).is(":checked")) {
            alert("true");
        } else {
            alert("false");
        }
    });
});
问题回答

由于网格没有将类应用到复选框中, 您可以做类似的事情 。

$(document).ready(function() {
    $(".checkbox :checkbox").click(function(){
        if (this.checked) {
            alert("true");
        } else {
            alert("false");
        }
    }); 
});
$(document).ready(function() {
    $("#chkselect").click(function(){
        if (this.checked) { // can also use $(this).is( :checked ) as you do
            alert("true");
        } else {
            alert("false");
        }
    }); // you code miss "});" here
});

您也可以使用选择器

$( : input: checkbox) $( 输入: checkbox) $( 输入: checkbox)





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签