我正在使用以下语句向页面添加复选框;
我需要在单击时获取该复选框的Text属性.我试过$(this).attr(‘Text’);在$(‘input [type = checkBox]’)中.单击(function(){});但它返回undefined.
我哪里错了?请建议.
干杯
最佳答案
ASP .NET将ASP:Check
Box服务器控件的Text
属性呈现为< input type =“checkbox”/>之后的
标签元素.在客户端
生成的
标记上,它看起来像这样:
Box" name="someId" />
您可以通过以下方式获取标签文本:
$("input:checkBox").click(function() {
var $label = $(this).next('label');
alert($label.text());
});