我通过ID名称匹配ASP.Net生成的元素,但有些元素可能会根据页面上下文呈现为文本框或标签。我需要弄清楚是匹配到文本框还是标签,以便知道是通过val()还是通过html()获得内容。
$("[id$=" + endOfIdToMatch + "]").each(function () {
//determine whether $(this) is a textbox or label
//do stuff
});
我找到了一个行不通的解决方案,它只会返回“ undefined”:
$("[id$=" + endOfIdToMatch + "]").each(function () {
alert($(this).tagName);
});
我想念什么?