[英]jquery selects returning undefined value - asp.net webform
簡單的jquery。 我有一個帶clss鏈接列表的div,里面有幾個鏈接按鈕
<script type="text/javascript">
$(function () {
$('#linklist a').each(function () {
alert(this.text);
});
});
</script>
我認為它應該警告每個渲染的超鏈接內的文本。 相反,我得到的值“未定義”
如果我改變它
alert(this.id);
我得到了正確的客戶ID - 因此我至少知道我選擇了正確的。 為什么這個值未定義? 同樣適用於this.text和this.value
謝謝
事件處理程序中的this
是本機DOM元素。
當你執行this.id
你將獲得DOMElement(錨點)的id
屬性。 不過,這並不有一個text
屬性。
要獲取錨的文本,請使用:
// turn "this" to a jquery object and use .text()
$(this).text()
或者保留原生javascript,你可以:
this.textContent || this.innerText
$(document).ready(function () {
$('.linklist a').each(function () {
alert(this.text);
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.