我有这样的表格:
<form id="loginCompact" action="https://externalsite..." name="sportsbook" method="post" onsubmit="createCookie('BRLOG', document.sportsbook.username.value, 1)">
<input type="text" name="username" class="loginUsername" />
...other fields...
</form>
这是被调用的 Javascript 函数:
<script type="text/javascript">
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/; domain='mydomain.com'";
}
</script>
但是,提交表单时没有设置 cookie。当附加到按钮的处理程序时它工作正常onclick
,但不是onsubmit
。有任何想法吗?