0
所以,我有一些JavaScript代碼,我用Greasemonkey在本地測試。但是,我得到這個錯誤持續在Firefox的錯誤控制檯:Javascript錯誤:catChildNotes [y] .setAttribute不是函數
catChildNotes [Y] .setAttribute不是一個功能
代碼:
var i = prompt("How many videos have you got?", "");
function remove_mp4()
{
titleElems=document.getElementsByName("title");
for(i=0; i<titleElems.length; i++)
{
titleInner=titleElems[i].innerHTML;
titleElems[i].innerHTML=titleInner.replace(titleInner.match(".mp4"), "");
}
}
for (var x = 0; x < i; i++)
{
document.getElementsByName("description")[x].value = "Visit me on my web-site :\
\
http://www.sample.com/";
document.getElementsByName("keywords")[x].value = prompt("Enter keywords : ","");
catChildNodes=document.getElementsByName("category")[x].childNodes;
catChildNodes[x + 1].removeAttribute("selected");
for(y=0; y<catChildNodes.length; y++)
{
if(catChildNodes[y].value="27")
{
catChildNodes[y].setAttribute("selected","");
}
}
}
remove_mp4();
該腳本應該在YouTube上運行上傳頁面並執行以下操作:
- 從標題中刪除「.mp4」
- 添加默認說明
- 添加關鍵字(這等於提示值)
- 更改類別爲「教育」
的機會是'catChildNodes [Y]'是不是你認爲它是和物業'setAttribute'被評估爲'undefined'。 。那麼* catChildNodes [y]'會評估什麼?爲什麼? – 2012-08-07 23:03:05
你是什麼意思?你能解釋一下好嗎? – TheGhost 2012-08-07 23:05:27
它評估在網頁的HTML元素中命名proprety。 Name屬性被設置爲「category」,所以它找到它並得到它的值。它的索引是var x,因爲x越來越多,所以如果我有10個視頻,x會先是0,然後是9,將我的所有視頻類別更改爲「Education」。希望我解釋得很好! :) – TheGhost 2012-08-07 23:09:00