<div class="clearText"><input type="text" /></div><script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.2.min.js"></script><script> (function () { $.fn.clearText = function () { return this.each(function () { var el = $(this), text, a = $('<a href="#" class="x">×</a>'); el.append(a); text = el.find(':text'); function inputEvent() { a[this.value == ''?'hide':'show'](); } text.bind({ input: inputEvent, propertychange: inputEvent, paste: inputEvent }); a.click(function () { text.val('').focus(); a.hide(); return false }); if (text.val() != '') a.show(); }); } })(jQuery); $('div.clearText').clearText();</script>
但是我看不懂,谁能帮忙下
这个是用来实现一键删除功能的
调试下,大概是显示一个对话框,然后确认下,删除你的数据,然后关闭它
这个代码格式,看到都够了,还注释啊??简直不能看下去。
那我重新发一份,稍等
这下能看清了,帮忙看看
(function () { $.fn.clearText = function () { return this.each(function () { var el = $(this), text, a = $('<a href="#" class="x">×</a>'); el.append(a); text = el.find(':text'); function inputEvent() { a[this.value == ''? 'hide':'show'](); } text.bind({ input: inputEvent, propertychange: inputEvent, paste: inputEvent }); a.click(function () { text.val('').focus(); a.hide(); return false }); if (text.val() != '') a.show(); }); } })(jQuery); $('div.clearText').clearText();这不是我写的吗。。就是给input对象添加x连接,点击x后就清空对应input的值,都是jquery的语法,自己看jquery api来看下就知道了。。
http://www.css88.com/jqapi-1.9/
参考jQuery中文API,有疑问可以先看下API。