繁体   English   中英

Javascript window.close()函数

[英]Javascript window.close() function

 function validateLoginForm(){ var str = ''; if(trim(document.getElementById('userName').value)=='') str = 'UserName is Required\\r\\n'; if(trim(document.getElementById('password').value)=='') str = str+'Password is Required'; if(str=='') return true; else{ alert(str); return false; } } function myOpenWindow() { var rand_no = Math.round(1000*Math.random()); if(window.name == "IMSWindowName"){ windowName = "IMSWindowNameFirst"+rand_no; windowName = "_self"+rand_no; }else{ windowName = "IMSWindowName"+rand_no; windowName = "_self"+rand_no; } heightVal=screen.height-150; widthVal=screen.width-150; newwin2 = window.open('',windowName,'toolbar=no,status=0,resizable=1,scrollbars=1,top=0,left=0,height='+heightVal+',width='+widthVal+''); document.forms[0].target=windowName; document.forms[0].action='LogIn'; document.forms[0].method='post'; newwin2.focus(); window.opener='X'; window.open('','_parent',''); window.close(); } 
 <input type=submit class="myButton" value="Sign In" title="Ok" onClick="if(validateLoginForm()){myOpenWindow();quitBox('quit');}else{return false;}"/></td><td><input type=button class="myButton" value="Clear" title="Reset" onClick="document.forms[0].reset();"/> 

我尝试使用此代码在登录时自动关闭登录窗口。此代码与IE浏览器完美配合,但在其他浏览器(例如chrome和firefox)中无法正常工作吗?

您可以使用此语法,

   if(document.getElementById('userName').value.trim()=='')

检查此链接以获取有关String.prototype.trim()的更多信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM