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