jquery检查是否选中了asp复选框 [英] jquery check if asp checkbox is checked

查看:57
本文介绍了jquery检查是否选中了asp复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个复选框,我想在回发之前检查它是否在客户端检查或不检查。
这是复选框:

Hello everyone I have a checkbox I want to check if its checked or no on client side, before postback happens. Here is the checkbox:

 <asp:CheckBox runat="server" CssClass="checkbox" Checked="true" ID="checkboxRules" />

提前致谢,Laziale

Thanks in advance, Laziale

更新:
问题是页面上还有一个由js代码触发的按钮,也许我可以在那里添加一行来检查单击按钮后是否选中了复选框,否则显示取消选中的消息复选框:

UPDATE: The problem is that there is a button on the page too which is triggered by js code, and maybe I can add a line there to check if the checkbox is checked once the button is clicked, otherwise display message for unchecked checkbox:

函数enterClick(){
$('#SUBMIT')。click();
}

function enterClick() { $('#SUBMIT').click(); }

var ishown = false;
$(document).ready(function () {
    $('#BUTTON').click(function (e) {

//我想把复选框逻辑放在这里

//I want to put the checkbox logic here

再次感谢

推荐答案

由于它是服务器端的复选框,它会发送类似< input type =checkboxclass =checkbox/> ; 在ASP.NET处理控件后作为HTML发送给客户端。

Since it is a server-side Checkbox, it will send something like <input type="checkbox" class="checkbox" /> as HTML to the client after ASP.NET processes the control.

复选框的id不会像你一样是checkboxRules在源代码中有它.ASP.NET将连接服务器端表单id +主页面id(如果使用母版页)+ checkboxRules,所以在这种情况下我不会使用依赖于元素id的选择器。

The id of the checkbox isn't going to be checkboxRules as you have it in the source code. ASP.NET will make a concatenation of the server-side form id + master page id (if using a master page) + checkboxRules so in this case I won't use a selector that depends on element id.

我们可以使jQuery选择器尽可能窄,只选择类型为checkbox且CSS类为checkbox的输入。

We can make a jQuery selector as narrow as possible to only select inputs with a type of "checkbox" and with a CSS class of "checkbox".

$('input[type=checkbox] .checkbox').attr('checked')

将返回输入检查状态的布尔值。这将在页面上找到该CSS类的复选框。

will return the boolean value of the check status of the input. This will find any input on the page that is a checkbox with that CSS class.

这篇关于jquery检查是否选中了asp复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆