本文介绍了为什么这不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 打开一个新窗口window_1,其中包含一个表单,使用窗口 引用更改值并提交,任何人都可以快速 glimse over this br / > windows打开确定,之后没有任何反应:( var window_1; //全局值 function function_1(){ window_1 = window.open(''http // ...''); setTimeout(function_2,10000); // 10秒加载 } 函数function_2() { window_1.forms [''postform'']。 elements [''commenttext'']。value =''test''; window_1.forms [''postform'']。submit(); } function_1在打开的窗口中的body onload中调用opens a new window window_1 which contains a form, uses windowreference to change values there and submits, anyone can have a quickglimse over thiswindows opens ok, nothing happens afterwards : (var window_1; // global valuefunction function_1() {window_1 = window.open(''http//...'');setTimeout(function_2, 10000); // 10 secs to load}function function_2(){window_1.forms[''postform''].elements[''commenttext''].value = ''test'';window_1.forms[''postform''].submit();}function_1 is called in body onload in the opened window推荐答案 i认为当你在做setTimeout()时你必须把代码放在 引号中,所以它应该是: setTimeout(" function_2( )",10000); 和在function_2中我认为你想做winow_1.document.forms而不是 比window_1.formsi think when you''re doing setTimeout() you have to put the code inquotes, so it should be:setTimeout("function_2()", 10000);and in function_2 i think you want to do winow_1.document.forms ratherthan window_1.forms i想你在做setTimeout()时你必须把代码放在 引号中,所以它应该是: setTimeout(" function_2()",10000);i think when you''re doing setTimeout() you have to put the code inquotes, so it should be:setTimeout("function_2()", 10000); 很容易测试是否应该引用它。在您选择的浏览器中尝试这个 代码: window.onload = testIt; function testIt(){ window.setTimeout(myFunction,1000) window.setTimeout(''myFunction2()'',2000) } function myFunction(){ alert(''没有引用'') } 函数myFunction2(){ alert(''引用'') }It is very easy to test whether it should be quoted or not. Try thiscode in the browser of your choice:window.onload=testIt;function testIt(){window.setTimeout(myFunction,1000)window.setTimeout(''myFunction2()'',2000)}function myFunction(){alert(''no quotes used'')}function myFunction2(){alert(''quotes used'')} 可能,但window_1.document.forms可能比winow_1更好.. - 兰迪 机会有利于预备心灵 comp.lang.javascript常见问题 - http://jibbering.com/faq/index.html Javascript最佳实践 - http://www.JavascriptToolbox.com/bestpractices/ 测试是否应该引用是非常容易的。在你选择的浏览器中试试这个 代码: window.onload = testIt; function testIt(){ window.setTimeout(myFunction,1000) window.setTimeout(''myFunction2()'',2000)} function myFunction(){ alert(''没有引用'')} 函数myFunction2(){ alert (''引用'') }It is very easy to test whether it should be quoted or not. Try thiscode in the browser of your choice:window.onload=testIt;function testIt(){window.setTimeout(myFunction,1000)window.setTimeout(''myFunction2()'',2000)}function myFunction(){alert(''no quotes used'')}function myFunction2(){alert(''quotes used'')} 可能,但window_1.document.forms可能比winow_1更好.. - 兰迪 机会有利于预备心灵 comp.lang.javascript常见问题-http:// jibbering.com/faq/index.html Javascript最佳实践-http://www.JavascriptToolbox.com/bestpractices/Possibly, but window_1.document.forms might work better than winow_1..--RandyChance Favors The Prepared Mindcomp.lang.javascript FAQ -http://jibbering.com/faq/index.htmlJavascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/ 这篇关于为什么这不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!