我有一个带有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>
Run Code Online (Sandbox Code Playgroud)
然后我有我的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;
}
Run Code Online (Sandbox Code Playgroud)
mailid
是一个全局变量,它在另一个JS函数中设置,它确实包含正确的值.怎么window.location
不打开我的页面?
如果我用mailid手动打开它可以正常工作..
Guf*_*ffa 56
设置位置工作正常,但随后提交表单,这将重新加载当前页面.
从方法返回false:
function sendmail() {
window.location.href = "http://www.rainbowcode.net/index.php/profiles/mail?="+mailid;
return false;
}
Run Code Online (Sandbox Code Playgroud)
并在事件中返回该状态以停止提交:
<input type="submit" value="Send" onclick="return sendmail()">
Run Code Online (Sandbox Code Playgroud)