如何确定在jQuery的匹配元素的元素类型?
问题描述:
我匹配ASP.Net生成由ID名称的元素,但我有可能会呈现为根据页面的上下文文本框或标签的一些元素。我需要弄清楚是否匹配是一个文本框或标签,以了解是否由VAL得到的内容()或HTML()。
I'm matching ASP.Net generated elements by ID name, but I have some elements which may render as text boxes or labels depending on the page context. I need to figure out whether the match is to a textbox or label in order to know whether to get the contents by val() or by html().
$("[id$=" + endOfIdToMatch + "]").each(function () {
//determine whether $(this) is a textbox or label
//do stuff
});
我发现不工作的解决方案,它只是返回未定义:
I found a solution that doesn't work, it just returns "undefined":
$("[id$=" + endOfIdToMatch + "]").each(function () {
alert($(this).tagName);
});
我是什么失踪?
答
刚一jQuery的太多:
Just one jQuery too much:
$("[id$=" + endOfIdToMatch + "]").each(function () {
alert(this.tagName);
});