插件 jQuery.rememberState 中文API文档
插件 jQuery.rememberState 中文API文档
- Github 地址:https://github.com/shaneriley/jquery_remember_state
- 源码下载: -
- 效果演示: -
jQuery表单记住状态插件
版本:1.4.1
在表单元素上调用时,localStorage用于记住已输入到保存或卸载点的值。(关闭窗口,导航等)如果localStorage不可用,则不会绑定或存储任何内容。
默认情况下,插件在表单中查找具有remember_state类的元素,以显示一条注释,指示存储的数据可以通过单击remember_state容器中的锚来重新填充。如果该元素不存在,则会创建该元素并将其添加到表单中。您可以覆盖选择器以及传递给插件的选项对象中预先添加的HTML。
选项
clearOnSubmit: true // Removes localStorage object when form submitted. Default is true
noticeDialog: $("<div />").html("<a href=\"#\">Restore</a>") // A newly created HTML element to represent the notice box prepended to the form. Must include an anchor for the user to choose to restore state
noticeSelector: ".remember_state" // If your noticeDialog already exists in the form, pass its selector here and clear out the noticeDialog option by setting it to false.
noticeConfirmSelector: "a" // Selector to use relative to the notice dialog to bind the confirm action to.
noticeCancelSelector: "" // Selector to use relative to the notice dialog to bind the cancel action to.
objName: "unique_form_name" // Specify a name for the localStorage object. If none is supplied, the form's ID will be used. If no ID is available, the plugin will fail, issuing a log explaining why.
ignore: null // Supply an array of name attributes for form controls that you'd like to ignore.
用法
$("form").rememberState("my_object_name");
要手动恢复保存的表单状态,而不是使用通知对话框:
$("form").rememberState("restoreState");
如果您想手动保存表单的状态,请在初始化后调用表单上的rememberState方法并将其传递给保存字符串,如下所示:
$("form").rememberState("save");
还有一种用于移除特定表单的绑定事件的拆卸方法。传递第二个参数true也会破坏该表单的localStorage对象。
$("form").rememberState("destroy", true);
笔记
要从插件外部触发删除表单的localStorage对象,请使用$(“form”)触发表单元素上的reset_state事件。触发器(“reset_state”);