获取复选框的文本属性
16lz
2021-01-22
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());
});
更多相关文章
- Jquery禁用/启用按钮与文本框代码
- jQuery中的bind绑定事件与文本框改变事件的临时解决方法
- 克隆文本并插入壁橱标题范围
- 如何删除/更改JQuery UI自动完成帮助文本?
- 将JSON结果返回给ajax请求的MVC ErrorHandling属性仅适用于local
- jQuery自动完成不适用于多个文本输入
- 如何使用jQuery UI插件使html文本框可拖动和调整大小?
- 在使用javascript将信息输入到输入字段时填充文本区域
- JQuery属性与样式――.val()和增加样式.addClass()