我想使用jQuery html()方法檢索整個頁腳標記內容,並且最終輸出應該位於一個變量中。jQuery鏈方法不起作用
我嘗試使用jQuery鏈方法,但它不工作。下面的代碼出了什麼問題。在使用jQuery html()
方法檢索後,鏈接不應該是可點擊的。
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
var footercontent = $('footer').html().removeAttr('href');
alert(footercontent);
});
</script>
</head>
<body>
<footer>
<a href="#">site Map</a> | <a href="#">Privacy stat</a> | <a href="#">Tutorials</a>
<p>Anchor tag link should be removed without content alignment changed.</p>
<p>This is another paragraph.</p>
<p>This is another paragraph.</p>
<p>Anchor tag link should be removed without content alignment changed.</p>
</footer>
</body>
</html>
的''
你試圖達到的目標也很不明確。你爲什麼要從所有的錨標籤中刪除'href'屬性? – Sparky 2014-10-07 02:51:26
'.html()',不帶參數調用,返回匹配元素的html。在這種情況下,您將'.removeAttr()'作爲未定義的字符串的方法調用,因此鏈斷裂。 - JAAulde 3 – JAAulde 2014-10-07 02:51:47