Mic*_*lia 2 javascript php cookies jquery
您好,我正在学习 jQuery,现在我正在尝试使用 jQuery Cookie 来设置表单输入值。
我已经能够使用以下方式从表单设置 cookie:
<script>
$(document).ready(function () {
$("#saveForm").click(function() {
$.cookie('myCookie', $("#element_1").val(), { expires: 365 });
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
我能够使用如下警报来验证 cookie:
<script>
alert( $.cookie("myCookie") );
</script>
Run Code Online (Sandbox Code Playgroud)
但是在这里搜索大量帖子后,我无法找到相同的问题,并且我查看了许多教程,但找不到用于设置表单中输入字段的值的代码。提前致谢!!
$(document).ready(function () {
$("#saveForm").click(function () {
$.cookie('myCookie', $el1.val(), {
expires: 365
});
});
//set the value of the cookie to the element element_1
var $el1 = $("#element_1").val($.cookie("myCookie"))
});
Run Code Online (Sandbox Code Playgroud)