我需要创建一个没有服务器或服务器端代码的用户登录表单。
为了做到这一点,我只是想把一个用户cookie设置到用户的IP上。我知道这不是最好的,但它应该足以收集公司内部登记表,为一个有趣的活动,对吗?
我只想要提交表格自动打开电子邮件与数据填入。但我只希望这种情况发生在独特的IP上,所以我打算将唯一的IP存储在cookie中10天。
由于某些原因,log(clientip)显示IP,但我不能将cookie设置为IP。为什么?它给出了错误:用于设置cookie的Uncaught TypeError: undefined is not a function ($.cookie("client_ip_cookie", clientip, { path: '/', expires : 10,});)
Index.html:收集IP:
<script type="application/javascript">
var clientip = "";
function getip(json){
clientip = json.ip;
}
</script>
<script type="application/javascript" src="http://jsonip.appspot.com/?callback=getip"> </script>提交表格:
<div class="eventForm">
<p>Name: <br> <input type="text" id="name" name="name" value=''></p>
<p>Email:<br> <input type="text" id="email" name="email" value=''></p>
<p>Message:<br><textarea id="message" name="message" rows=8 cols=30></textarea></p>
<button id="submitBtn" value="Submit" name='submit'>Submit</button>
</div> JavaScript:
$("#submitBtn").click(function (event) {
log(clientip); //logs IP
$.cookie("client_ip_cookie", clientip, { path: '/', expires : 10});
//if (clientip is not on page, then log these credentials)
var subject = "Registration for Walk-a-thon",
name = document.getElementById("name").value,
email = document.getElementById("email").value,
message = document.getElementById("message").value;
var link = "mailto:testemail@aol.com"
+ "?cc=myemail@aol.com"
+ "&subject=" + escape(subject)
+ "&body=" + escape(message)
;
window.location.href = link;
});发布于 2014-05-02 00:34:14
如果您的页面没有加载jquery.cookie插件,那么$.cookie将是未定义的。
包括脚本
<script src="/path/to/jquery.cookie.js"></script>在jQuery库之后
https://stackoverflow.com/questions/23415630
复制相似问题