是否可以使用jQuery设置"for"(AssociatedControlID)属性?我正在尝试将其设置为显示在label之后的下一个控件:
$('label.asssociateClass').each(function()
{
var toAssociate = $(this).next(':input');
$(this).attr("for", toAssociate.attr("id"));
});
问题是,如果我不通过AssociatedControlID在服务器上设置它,它永远不会出现在这里,因为在这种情况下,它呈现为span
而不是label
。有没有办法克服这个问题,或者我必须在服务器上解决这个问题?
发布于 2010-04-08 07:30:40
可以使用.replaceWith()
将跨度替换为标签,如下所示:
$('span.asssociateClass').each(function() {
var l = $("<label class='associateClass' />")
.html($(this).html())
.attr('for', $(this).next(":input").attr("id"));
$(this).replaceWith(l);
});
下面是一个简单的例子:http://jsfiddle.net/V73WL/
发布于 2010-04-08 07:18:27
您不能更改asp:label的行为,但是可以使用jquery更改标签
$(function () {
var spans = $('span.label').each(function() {
input = $(this).next('input');
$('<label />').html($(this).html()).attr('for', input.attr('id')).insertBefore(input);
$(this).remove();
});
});
https://stackoverflow.com/questions/2596545
复制相似问题