前些天在做项目的时候要使用JS给SELECT动态添加OPTION,遇到了个问题,JS代码如下:
while (obj.selectedIndex > -1){ mot = obj.options[obj.selectedIndex].text; mov = obj.options[obj.selectedIndex].value; obj.remove(obj.selectedIndex); var newoption = document.createElement("OPTION"); newoption.text = mot; newoption.value = mov; target.add(newoption); }
而Firefox却不认
target.add(newoption);
出错提示:
uncaught exception: [Exception... "Not enough arguments" nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)" location: "JS frame :: http://localhost/untitled.asp :: moveselect :: line 23" data: no]
修改代码如下:
while (obj.selectedIndex > -1){ mot = obj.options[obj.selectedIndex].text; mov = obj.options[obj.selectedIndex].value; obj.remove(obj.selectedIndex); var newoption = document.createElement("OPTION"); newoption.text = mot; newoption.value = mov; if(Sys.ie) target.add(newoption); if(Sys.firefox) target.appendChild(newoption); }
谢谢各位!是鄙人寡闻了