jquery-clear-default-input-values-once
来源:互联网 发布:嵌入式linux启动美化 编辑:程序博客网 时间:2024/06/10 11:09
原文地址:http://www.jotlab.com/2010/jquery-clear-default-input-values-once
中文搜索这个出不来,不知道怎么描述了,直接用英文题目了。就是清除表单默认值一次。。。。
I like to have default values in my text input fields. However it is an annoying user experience to have to manually clear the value out and then enter in the value. Instead I thought I would write a simple script that would work site wide to clear out the default values. You of course will need your jquery included:
Following some brilliant comments on this there is a much quicker method:
$(
'input[type=text]'
).one(
'focus'
,
function
(){
$(
this
).attr(
'value'
,
''
);
});
However the original code I came up with is as follows:
$(
function
(){
$(
'input[type=text]'
).focus(
function
(){
if
(!
this
.clicked) {
$(
this
).attr(
'value'
,
''
);
this
.clicked =
true
;
}
});
});
This will clear the fields out only once. So if the user enters a value, then focuses back on the field, their values won’t be cleared. So if they needed to edit a single letter, then their entire entry won’t be wiped. If you have any hints feel free to comment
然后,我改了一点东西,因为我有密码输入也需要清空。$(function(){
$('input').focus(function(){
if (!this.clicked) {
$(this).attr('value', '');
this.clicked = true;
}
});
});
不知道为什么 $(this).attr('value', '');在IE10下面不管用,然后改成$(this).val('');才正常
效果还不错。。。
- jquery-clear-default-input-values-once
- Python Default Argument Values
- python function default values
- input tensor values 困惑
- 12.2 Default values?Static variables.
- Default Parameter Values in Python
- 0804-APP-Preference-default-values
- Java - Default Values and Initialization
- jquery datepicker clear date
- java eight data types default values
- The default values for java data types:
- Define default values for buyers - OMFI (EVO)
- What Are the Default HotSpot JVM Values
- Linux串口工具cutecom--clear input history
- AngularJs clear input in ng-repeat
- Clear a form with jQuery
- Adding Expressions, Default Values and Constraints to a Table
- The default keys and values of java system properties
- java 网络抓包
- cocos2d游戏开发,常用工具集合
- SET IDENTITY_INSERT-学习心得
- 网站的分布式架构
- 基于HELP 2416 MDK 4.01 uCOS II V2.9 的移植
- jquery-clear-default-input-values-once
- Git在Merge时提示(no branch)差点丢失数据,后找回
- WebService流行框架之Axis和CXF
- MFC 多线程及线程同步
- 共享一段CMPP编程时候,移动网关返回CMPP_SUBMIT_RESP消息中,解析Msg_Id字段的代码
- ScrollView中嵌套ListView造成ListView高度只显示一行解决办法
- lucene 4.3.0 demo 解析
- 函数指针讲解
- 熟练使用spring Aop