data存储数据DEMO 获得光标文本消失

<!doctype html public "-//w3c//dtd html 4.0 transitional//en"><html><head><meta http-equiv="expires" content="fri, jan 01 1900 00:00:00 gmt"><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta http-equiv="lang" content="en"><meta name="author" content=""><meta http-equiv="reply-to" content="@.com"><meta name="generator" content="phped 5.6"><meta name="description" content=""><meta name="keywords" content=""><meta name="creation-date" content="11/11/2008"><meta name="revisit-after" content="15 days"><title>untitled</title><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"type="text/javascript"></script></head><body><form id="testform">    <input class="clear" type="text" value="always cleared" />    <input class="clear once" type="text" value="cleared only once" />    <input type="text" value="normal text" /></form><script type="text/javascript">jquery.fn.log = function (msg) {console.log("%s: %o", msg, this);return this;};  $(function() {    //go through every input field with clear class using each function    //(nb! "clear once" is two classes clear and once)    $('#testform input.clear').each(function(){        //use the data function to save the data        $(this).data( "txt", $.trim($(this).val()) );    }).focus(function(){        // on focus test for default saved value and if not the same clear it        if ( $.trim($(this).val()) === $(this).data("txt") ) {            $(this).val("");        }    }).blur(function(){        // use blur event to reset default value in field that have class clear        // but ignore if class once is present        if ( $.trim($(this).val()) === "" && !$(this).hasclass("once") ) {            //restore saved data            $(this).val( $(this).data("txt") );        }    });});  var input_text = $('#shopping_cart_items input.text');input_text    .css('border', '3px dashed yellow')    .css('background-color', 'red')    .val("text updated");  </script></body></html>
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值