Asp.net
如何確定 jQuery 中匹配元素的元素類型?
我正在按 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); });我錯過了什麼?
一個 jQuery 太多了:
$("[id$=" + endOfIdToMatch + "]").each(function () { alert(this.tagName); });