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 GreenDao 使用例子 Android Gree
  3. 谷歌Android系统版本无序发展反噬产业链
  4. linux android 下进入android shell
  5. Android rxjava实现倒计时功能
  6. android 转屏问题
  7. 图片切换
  8. Android SetWallpaper
  9. Android 设置边距总结
  10. Android(安卓)实现沉浸式体验