使用onmouseover事件從<a>
標籤獲取地址值的最佳方式是什麼?使用onmouse獲取地址的問題
<a href="http://facebook.com" onmouseover="">something</a>
使用onmouseover事件從<a>
標籤獲取地址值的最佳方式是什麼?使用onmouse獲取地址的問題
<a href="http://facebook.com" onmouseover="">something</a>
<a href="http://facebook.com" onmouseover="alert(this.getAttribute('href'))">something</a>
您可以使用此結果存儲在變量下面的代碼:
document.getElementsByTagName('a')[0].onmouseover = function() {
var hrefValue = this.getAttribute('href');
alert(hrefValue); // use hrefValue
}
也許你可以說如何將這個結果存儲在變量中? –
答覆已更新。 –
<a href="http://facebook.com" onmouseover="alert($(this).text())">something</a>
$(this).text()
獲取a
標籤和alert
之間的文本彈出警報框以確保其正常工作。替代將是console.log()
的值。這種方式不是那種侵入性的。
請考慮編輯您的帖子以添加更多關於您的代碼的解釋以及爲什麼它可以解決問題。一個主要包含代碼的答案(即使它正在工作)通常不會幫助OP瞭解他們的問題。 – SuperBiasedMan
可能重複[顯示在HTML中的圖像的MouseOver文本](http://stackoverflow.com/questions/12105214/display-text-on-mouseover-for-image-in-html) – jkalden