- $(document).ready(function() {
- //each遍历文本框
- $(".input").each(function() {
- //保存当前文本框的值
- var vdefault = this.value;
- $(this).focus(function() {
- //获得焦点时,如果值为默认值,则设置为空
- if (this.value == vdefault) {
- this.value = "";
- }
- });
- $(this).blur(function() {
- //失去焦点时,如果值为空,则设置为默认值
- if (this.value == "") {
- this.value = vdefault;
- }
- });
- });
- });
- //该片段来自于http://www.codesnippet.cn/detail/090520133212.html
来源: http://www.codesnippet.cn/detail/090520133212.html