对于自动保存表单的某些javascript,我收到以下错误。
未捕获的TypeError。对象[对象对象]没有方法'自动保存'
在标题中我有这个:
<script type="text/javascript" src="../js/jquery.autosave.js"></script>
我也在标题中包含了所有正确的jquery文件。 在正文中,这是给出错误的部分
<script type="text/javascript">
$(function(){
$("input,select,textarea").autosave({
url: "autosave2.php",//set the php file that updates the database
method: "post",
grouped: true,//send data for all fields with the autosave
success: function(data) {//on a successful update...
$("#message").html("Data updated successfully").show();//...show a message...
setTimeout('fadeMessage()',1500);//...and then fade it out after an interval
},
send: function(){//on a save...
$("#message").html("Sending data....");//..show a message
},
dataType: "html"
});
});
function fadeMessage(){
$('#message').fadeOut('slow');//just a function to fade out the message
}
</script>
值得注意的是,如果我手动提交表单,它就可以工作,所以我知道autosave2.php文件可以正常工作。
在回复有关jquery的评论时,autosave.js文件确实出现在标题中的jquery之后:
<script type="text/javascript" src="../jquery/jquery-1.9.1.js"></script>
<script type="text/javascript" src="../jquery/jquery-ui-1.10.2.custom.js"></script>
<script type="text/javascript" src="../js/jquery.autosave.js"></script>
<SCRIPT LANGUAGE="JavaScript" SRC="../js/CalendarPopup.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
var cal = new CalendarPopup();
</SCRIPT>
<script type="text/javascript" src="../js/formvalidator.js"></script>
</head>
这就是autosave.js中的内容:
(function($) {
$.fn.autoSave = function(callback, ms) {
return this.each(function() {
var timer = 0,
$this = $(this),
delay = ms || 1000;
$this.keyup(function() {
clearTimeout(timer);
var $context = $this.val();
if(localStorage) {
localStorage.setItem("autoSave", $context);
}
timer = setTimeout(function() {
callback();
}, delay);
});
});
};
})(jQuery);