本文介绍了需要帮助..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个Javascript函数,它将表单的文本字段更改为 一个选择字段。以下是函数 函数changeStateField() { var myForm = document.getElementsByTagName("表格)[0]; alert(myForm.stateId.value); myForm.removeChild(myForm.stateId); var stateSelect = document.createElement(" select"); stateSelect.setAttribute(" stateId2"," stateId"); myForm.insertBefore(stateSelect,myForm.countyId); } 函数在alert中显示正确的值。但在第3行 myForm.removeChild(myForm.stateId); 它给出了以下错误。我正在使用Firefox。 错误:未捕获的异常:[异常...未找到节点代码: " 8" nsresult:" 0x80530008(NS_ERROR_DOM_NOT_FOUND_ERR)" location: " http:// localhost:8080 / APP / premiseCatalog.do Line:245"] 我们将非常感谢您的帮助。 问候, Naeem。 解决方案 你必须向我们展示html。 - Evertjan。 荷兰。 (请更改x 我的电子邮件中的点数 document.forms [0] //更简单:) Firefox告诉你尚未找到该节点;正如Evertjan所说, 问题在于你的HTML,你的stateId元素的父元素 可能是形式之外的其他元素。 --- < head> < script type =" text / javascript"> var foo =(function(){ var cached_select = createElement( "< select name =''stateId''>< option value =''hello' '> Hello< \ / select>" ); var cached_input = createElement( "< ; input type =''text''name =''stateId''>" ); function createElement(str){ var div = document.createElement(" div"); div.innerHTML = str; return div.firstChild; } 返回功能(表格){ var el,type = form.stateId.nodeName.toLowerCase(); form.removeChild(form.stateId); 开关(类型){ case input:el = cached_select;休息; case" select" :el = cached_input;休息; } form.insertBefore(el,form.firstChild); } })( ); < / script> < / head> < body> < form action ="#"> < input type =" text" name =" stateId"> < input type =" button"值= QUOT;切换" onclick =" foo(this.form)"> < / form> < / body> --- I have a Javascript function, which changes a text field of a form intoa select field. Following is the functionfunction changeStateField(){var myForm = document.getElementsByTagName("form")[0];alert(myForm.stateId.value);myForm.removeChild(myForm.stateId);var stateSelect = document.createElement("select");stateSelect.setAttribute("stateId2", "stateId");myForm.insertBefore(stateSelect, myForm.countyId);}Function displays the correct value in alert. but on line 3myForm.removeChild(myForm.stateId);it gives following error. I am using Firefox.Error: uncaught exception: [Exception... "Node was not found" code:"8" nsresult: "0x80530008 (NS_ERROR_DOM_NOT_FOUND_ERR)" location:"http://localhost:8080/APP/premiseCatalog.do Line: 245"]Your help will be greately appreciated.Regards,Naeem. 解决方案You will have to show us the html too.--Evertjan.The Netherlands.(Please change the x''es to dots in my emailaddress)document.forms[0] // simpler :)Firefox tells you that the node has not been found; as Evertjan said,the problem lies with your HTML, the parent of your stateId elementprobably being some other element than the form.---<head><script type="text/javascript">var foo=(function(){var cached_select=createElement("<select name=''stateId''><option value=''hello''>Hello<\/select>");var cached_input=createElement("<input type=''text'' name=''stateId''>");function createElement(str) {var div=document.createElement("div");div.innerHTML=str;return div.firstChild;}return function(form){var el, type=form.stateId.nodeName.toLowerCase();form.removeChild(form.stateId);switch (type) {case "input" : el=cached_select; break;case "select" : el=cached_input; break;}form.insertBefore(el,form.firstChild);}})();</script></head><body><form action="#"><input type="text" name="stateId"><input type="button" value="Toggle" onclick="foo(this.form)"></form></body>--- 这篇关于需要帮助..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!