Sisyphus.js的使用

1、引入js

建立html页面test.html文件,并且引入jquery和sysyhpus以及html文件对应的test.js文件

<script type="text/javascript" src="jquery-3.1.1.js" ></script>
<script type="text/javascript" src="sisyphus.js" ></script>
<script type="text/javascript" src="test.js" ></script>

2、支持的控件以及写法

文本框、复选框、单选框、textarea等都可以保持数据缓存。也可以在js里面控制哪些是不保持的。

<form id="aaa">
    aa:<input name="aa" id="aa" /><br>
    bb:<input type="password" name="password" id="bb" /><br>
    cc:<select id="cc">
        <option value="1" >hahaha111111</option>
        <option value="2">hahaha222222</option>
        <option value="3">hahaha333333</option>
        <option value="4">hahaha444444</option>
        <option value="5">hahaha555555</option>
    </select><br>
    dd:<input type="checkbox" name="dd" value="111" id="c1" >哈哈11
    <input type="checkbox" name="dd" value="222" id="c2">哈哈22
    <input type="checkbox" name="dd" value="333" id="c3" >哈哈33
    <input type="checkbox" name="dd" value="444" id="c4" >哈哈44
    <input type="checkbox" name="dd" value="555" id="c5" >哈哈55<br>
    ee:<input type="radio" name="ee" value="11">呵呵11
    <input type="radio" name="ee" value="22" >呵呵22
    <input type="radio" name="ee" value="33" >呵呵33
    <input type="radio" name="ee" value="44">呵呵44
    <input type="radio" name="ee" value="55">呵呵55<br>
    ff:<input type="file" name="ff" id="ff123" /><br>
    gg:<textarea rows="2" cols="20" name="gg" id="gg"></textarea>
    <button type="button" οnclick="test()" >hehe</button>
</form>

例如:在sysyphus中,去掉password就可以缓存密码。

findFieldsToProtect: function( target ) {
                    return target.find( ":input" ).not( ":submit" ).not( ":reset" ).not( ":button" ).not( ":file" ).not( ":password" ).not( ":disabled" ).not( "[readonly]" );
                }

 

3、js加载

form表单的id直接加载。并且可以设置多长时间自动保存,并且提示自动保存框

$(function(){
    $( "#aaa" ).sisyphus({
        locationBased: true, 
        excludeFields: $( "#c1" ), //排除
        timeout: 10,
        onBeforeSave: function() {
            console.log("开始保存"+new Date());
            }
    });
});

4、效果展示

即使关掉页面,再打开依然可以保持数据的已有数据的状态

131534_YsX4_2404345.png

 

转载于:https://my.oschina.net/Seaside20151225/blog/813669

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值