清除输入字段,但“提交”按钮除外

杰里米

我有一些jQuery设置来自动清除输入表单中的默认值。但是,在Chrome中,它也适用于“提交”按钮。因此,每当用户单击提交时,按钮都会丢失其值并缩小。

这是我的代码:

jQuery(document).ready(function() {

jQuery.fn.cleardefault = function() {
return this.focus(function() {
    if( this.value == this.defaultValue ) {
        this.value = "";
    }
}).blur(function() {
    if( !this.value.length ) {
        this.value = this.defaultValue;
    }
});
};
jQuery("input, textarea").cleardefault();
});

这是带有工作示例的CodePen-如您所见,它只是Chrome中的一个问题:http : //codepen.io/anon/pen/hoJFB/

阿德内

仅排除提交按钮,您可以执行

jQuery('input:not([type="submit"]), textarea').cleardefault();

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章