jQuery来得到一个复选框的文本属性 [英] jQuery to get the text attribute of a checkbox

查看:93
本文介绍了jQuery来得到一个复选框的文本属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的语句添加一个复选框,一个页面;

I'm adding a check box to a page using the following statement;

<script language="C#" runat="server">
    protected void Page_Load ( object src, EventArgs e ) 
    {
        if (!IsPostBack)
        {
         CheckBox XChkBox = new CheckBox(); //instance of System.Web.UI.WebControls.CheckBox
         XChkBox.ID = "someId"
         XChkBox.Text = "someText"
         somePlaceHolder.Controls.Add(XChkBox);
        }
    }
</script>

我需要获得点击的复选框的Text属性。我试图 $(本).attr(文本); $('输入[类型=复选框]')点击(函数( ){}); ,但它返回undefined

I need to get the Text attribute of that check box on click. I tried $(this).attr('Text'); inside $('input[type=checkbox]').click(function(){}); but it returns undefined.

我在哪里去了?请建议。

Where am I going wrong? Please suggest.

欢呼声

推荐答案

ASP .NET呈现 ASP的文本属性:复选框服务器控件,作为标签元素刚过&LT;输入类型=复选框/&GT; 上的客户端生成的标记,它看起来是这样的:

ASP .NET renders the Text property of the ASP:CheckBox server control, as a label element just after the <input type="checkbox" /> on the generated markup at the client, it looks something like this:

<input id="someId" type="checkbox" name="someId" />
<label for="someId"> someText </label>

您可以得到文本标签

$("input:checkbox").click(function() {
  var $label = $(this).next('label');
  alert($label.text());
});

这篇关于jQuery来得到一个复选框的文本属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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