我似乎无法得到这个工作:下面的代码:jQuery回调函数?
// Clears the default text on click, but restores if nothing is entered
var clearText = (function(){
$("input:text").each(function() {
var default_value = this.value;
$(this).focus(function(){
if(this.value == default_value) {
this.value = '';
}
});
$(this).blur(function(){
if(this.value == '') {
this.value = default_value;
}
});
});
$("textarea").each(function() {
var default_value = this.value;
$(this).focus(function(){
if(this.value == default_value) {
this.value = '';
}
});
$(this).blur(function(){
if(this.value == '') {
this.value = default_value;
}
});
});
})();
$('html').on('keydown', 'body', function(e){
if (e.which == 9)
{
clearText();
}
});
明文()肯定是被称为在页面加载,但随后并没有作为一个回调函数工作呢?我不完全确定为什么,有谁能帮我解决问题?
干杯
有没有一种方法可以让它在自定义时自动调用,并且使clearText成为一个函数? – chintanparikh 2012-02-19 07:42:39
是的,有几种方法可以做到这一点。但是不要保存一行代码是不值得的,它有点神秘。定义函数并调用它们。那就是人的思维是如何运作的。只需添加clearText();在你定义它之后,每个人都会知道发生了什么。 – 2012-02-19 07:48:18
哎呀,感谢您的帮助 – chintanparikh 2012-02-19 07:50:27