因此,我正在爲網站編寫一個userscript,並且遇到此錯誤Uncaught TypeError: is not a function
它不會在Firefox中發生,但會在Chrome中發生。我花了最後一個小時調試沒有成功。Uncaught TypeError:不是Chrome中的功能
我已經提供了下面的相關代碼片段來重現chrome中的錯誤。該腳本應該找到包含文本「下載」的按鈕並返回href。
function getSubmissionSource(){
var controlBar = document.getElementsByClassName("button submission rounded");
for (var button of controlBar) { //errors here
var link = button.getElementsByTagName("a")[0];
if (link !== undefined && link.textContent == "Download") {
return link.href;
}
}
}
console.log(getSubmissionSource());
<div id="test"">
<span class="button submission rounded">
<a href="/view/18251152/" class="prev dotted">Older</a>
</span>
<span class="button submission rounded">
<a href="">-Remove from Favorites</a>
</span>
<span class="button submission rounded">
<a href="">Download</a>
</span>
<span class="button submission rounded">
<a href="">Note user</a></span>
<span class="button submission rounded">
<a href="/view/18385008/">Newer</a>
</span>
</div>
你試圖改變'爲(VAR button'成'爲(btn'? – Justinas