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>

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.

我需要在单击时获取该复选框的文本属性。我试着(美元).attr(“文本”);在$(“输入(type =复选框)”).click(函数(){ });但它返回定义。

Where am I going wrong? Please suggest.

我哪里做错了?请建议。

cheers

干杯

3 个解决方案

#1


10

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:

net将ASP:CheckBox服务器控件的文本属性呈现为一个标签元素,就在客户端生成的标记上的之后,它看起来是这样的:

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

You can get the text of the label by:

你可透过以下途径取得标签的文本:

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

更多相关文章

  1. Jquery禁用/启用按钮与文本框代码
  2. jQuery中的bind绑定事件与文本框改变事件的临时解决方法
  3. 克隆文本并插入壁橱标题范围
  4. 如何删除/更改JQuery UI自动完成帮助文本?
  5. 将JSON结果返回给ajax请求的MVC ErrorHandling属性仅适用于local
  6. jQuery自动完成不适用于多个文本输入
  7. 如何使用jQuery UI插件使html文本框可拖动和调整大小?
  8. 在使用javascript将信息输入到输入字段时填充文本区域
  9. JQuery属性与样式――.val()和增加样式.addClass()

随机推荐

  1. Android打开系统设置界面
  2. android-性能优化之merge
  3. android studio系列之使用指南
  4. Android 支付宝App支付集成
  5. Android 分页组件
  6. android反编译与加固(Mac版)
  7. Android常见布局简述
  8. Android中文文档v0.1 beta低调发布,期待
  9. Android可收缩/扩展的TextView【2】
  10. 《宅男的android开发指南》(翻译)--1