2011-06-03 70 views
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

回答

0

我想你应该通过option(不optionText)至add()方法。

+0

非常感谢您的帮助和对于愚蠢的问题对不起:)晚上工作有时会导致真正愚蠢的错误... – Rizar 2011-06-04 08:04:30