window.location()不工作,不打开页面 [英] window.location() not working, not opening page

查看:93
本文介绍了window.location()不工作,不打开页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有onClick的提交按钮:

 < div id =messageDiv> 
< form>
< textarea name =messagerows =10cols =20>< / textarea>< / textarea>
< br />< br />
< input type =submitvalue =SendonClick =sendmail()>
< input type =resetvalue =Resetname ='reset'>
< / form>
< / div>

然后我有我的sendmail:

  function sendmail()
{
window.location.href =http://www.rainbowcode.net/index.php/profiles/mail?=\"+ mailid;
window.location('http://www.rainbowcode.net/index.php/profiles/mail?='+mailid);
//返回true;
}

mailid 是一个在另一个JS函数中设置的全局变量,它包含正确的值。如何 window.location 不打开我的页面?



如果我用mailid手动打开它,它可以正常工作..

解决方案

设置位置工作得很好,但随后表单被提交,它将重新加载当前页面。

返回false:

  function sendmail(){
window.location.href =http://www.rainbowcode.net/index.php/profiles/mail?=\"+mailid;
返回false;
}

并返回该状态以停止提交:

 < input type =submitvalue =发送onclick =return sendmail()> 


I have a submit button with a onClick:

<div id="messageDiv">
<form>
<textarea name="message" rows="10" cols="20"></textarea></textarea>
<br /><br />
<input type="submit" value="Send" onClick="sendmail()">
<input type="reset" value="Reset" name='reset'>
</form>
</div>

then I have my sendmail:

   function sendmail()
   {   
      window.location.href = "http://www.rainbowcode.net/index.php/profiles/mail?="+mailid;
      window.location('http://www.rainbowcode.net/index.php/profiles/mail?='+mailid);
      //return true;
   }

mailid is a global variable that gets set in another JS function and it does contain the correct value. How come window.location is not opening my page?

If I manually open it with a mailid it works fine..

解决方案

Setting the location works just fine, but then the form is submitted, which will reload the current page instead.

Return false from the method:

function sendmail() {   
  window.location.href = "http://www.rainbowcode.net/index.php/profiles/mail?="+mailid;
  return false;
}

and return that status in the event to stop the submit:

<input type="submit" value="Send" onclick="return sendmail()">

这篇关于window.location()不工作,不打开页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆