问题描述
我要实现多选项卡登录,选择不同选项卡,填写密码、用户名后,点击登录到不同的地方。功能在IE内核的浏览器好用,在chrome内核浏览器时报错如下:1、点击选项卡时报错:cannot call method 'getElementById' of undefined。2、输入密码登录时,页面只刷新,不转跳。代码如下:<head><script type="text/javascript">function qhdt1(a){for(var i=1;i<5;i++){this.document.getElementById("dltp"+i).src="<%=request.getContextPath()%>/image/dl-04-"+i+"-1.gif";}this.document.getElementById("lb").value=a;this.document.getElementById("dltp"+a).src="<%=request.getContextPath()%>/image/dl-04-"+a+"-2.gif";hello.querylogin(a,test3);}function test3(data){//alert();this.document.getElementById("logindiv").innerHTML=data;//alert(document.getElementById("logindiv").innerHTML);}function tj(){var lb=this.document.getElementById("lb").value;alert(lb);var yhm=this.document.getElementById("yhm");if(ChkUtil.isNull(yhm.value)){alert("登录名称不能为空");yhm.focus();return;}var mm=this.document.getElementById("mm");if(ChkUtil.isNull(mm.value)){alert("密码不能为空");mm.focus();return;}if(lb==1){this.document.thisform.password.value = mm.value ;alert(mm.value);this.document.thisform.user.value = yhm.value ;alert(yhm.value);this.document.thisform.action="http://mail.hljbsm.gov.cn/?q=login.do";this.document.thisform.submit();this.window.location.href="qt_index.jsp";}.......}</script ><body><table width="970" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="525"><table width="525" border="0" align="left" cellpadding="0" cellspacing="0"> <tr> <td colspan="2"><table width="525" border="0" cellspacing="0" cellpadding="0"> <tr> <td><a onclick="qhdt1(1)"><img src="<%=request.getContextPath()%>/image/dl-04-1-2.gif" width="116" height="24" border="0" id="dltp1" /></a></td> <td><a onclick="qhdt1(3)"><img src="<%=request.getContextPath()%>/image/dl-04-3-1.gif" width="116" height="24" border="0" id="dltp3" /></a></td> <td><a onclick="qhdt1(4)"><img src="<%=request.getContextPath()%>/image/dl-04-4-1.gif" width="155" height="24" border="0" id="dltp4" /></a></td> <td><a onclick="qhdt1(2)"><img src="<%=request.getContextPath()%>/image/dl-04-2-1.gif" width="138" height="24" border="0" id="dltp2" /></a></td> </tr> </table></td> </tr> <tr> <td width="6"><img src="<%=request.getContextPath()%>/image/dl-02.gif" width="6" height="36" /></td> <td width="519" background="<%=request.getContextPath()%>/image/dl-01.gif"><table width="510" border="0" align="left" cellpadding="0" cellspacing="0"> <form method=post action="" name="thisform" target="_blank"><!--tr> <td width="102"><img src="<%=request.getContextPath()%>/image/dl-biao.gif" width="102" height="27" /></td> <td width="70" align="right" class="text-12-hui" style="padding-top:3px;">用户名:</td> <td width="82"><label> <input name="yhm" id="yhm" type="text" size="10" /> </label></td> <td width="54" align="right" class="text-12-hui" style="padding-top:3px;">密 码:</td> <td width="92"><input name="mm" id="mm" type="Password" size="10" /></td> <td width="59"><a href="javascript:tj()"><img src="<%=request.getContextPath()%>/image/dl-an-1.gif" width="48" height="21" border=0/></a></td> <!--td width="51"><img src="<%=request.getContextPath()%>/image/dl-an-2.gif" width="48" height="21" /></td--> </tr--> <tr> <td><div id="logindiv"><table><tr> <td width="102"><img src="<%=request.getContextPath()%>/image/dl-biao.gif" width="102" height="27" /></td> <td width="70" align="right" class="text-12-hui" style="padding-top:3px;">用户名:</td> <td width="82"><label> <input name="yhm" id="yhm" type="text" size="10" /> </label></td> <td width="54" align="right" class="text-12-hui" style="padding-top:3px;">密 码:</td> <td width="92"><input name="mm" id="mm" type="Password" size="10" style="height:15px;" /></td> <td width="59"><a href="javascript:tj()"><img src="<%=request.getContextPath()%>/image/dl-an-1.gif" width="48" height="21" border=0/></a></td> <!--td width="51"><img src="<%=request.getContextPath()%>/image/dl-an-2.gif" width="48" height="21" /></td--> </tr> </table></body> 问题补充:cloverprince 写道
解决方案
document.thisform.action="http://mail.hljbsm.gov.cn/?q=login.do"; document.thisform.submit(); window.location.href="qt_index.jsp"; 这个有问题,window.location.href="qt_index.jsp";这个已经是在document.thisform.submit()之后了,你又在同一个页面上所以qt_index.jsp永远也到不了提交时直接document.thisform.action= "qt_index.jsp";或者document.thisform.target="_aaa";document.thisform.action="http://mail.hljbsm.gov.cn/?q=login.do"; document.thisform.submit(); window._aaa.close();window.location.href="qt_index.jsp";看行不行
解决方案二:
楼主对this的理解还不是很到位~~~~http://www.jb51.net/article/19425.htm
解决方案三:
不要this,直接document.getElementById。