1
下面的腳本獲取這樣的錯誤消息話題:傳遞nsIDOMHTMLSelectElement作爲函數參數將導致異常
uncaught exception: [Exception... "Could not convert JavaScript argument arg 0
[nsIDOMHTMLSelectElement.add]" nsresult:
"0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location:
"JS frame :: file:///D:/programming/temp/js_bug/page.html
:: addOption :: line 13" data: no]
一塊HTML的腳本具有:
<form name = "form">
<select name = "select">
</select>
</form>
<script>
//This way of adding an option fails
function addOption(selectElement, optionText)
{
var option = document.createElement("option")
option.text = optionText
selectElement.add(optionText, null);
}
element = document.getElementsByName("select")[0]
addOption(element, "2")
/* This way of adding an option works
option = document.createElement("option")
option.text = "1"
element.add(option, null)*/
</script>
的註釋的代碼正常工作。我只能看到工作的代碼和失敗的代碼之間的區別 - 傳遞DOM對象作爲函數參數。
我工作的火狐3.6.17
非常感謝您的幫助和對於愚蠢的問題對不起:)晚上工作有時會導致真正愚蠢的錯誤... – Rizar 2011-06-04 08:04:30