admin管理员组文章数量:1290945
I am using this javascript to empty an input/textarea when focussed.
$(document).ready(function() {
$('input[type="text"],textarea').not('[readonly="readonly"]').addClass("idleField");
$('input[type="text"],textarea').focus(function() {
$(this).removeClass("idleField").addClass("focusField");
if (this.value == this.defaultValue){
this.value = '';
}
if(this.value != this.defaultValue){
this.select();
}
});
$('input[type="text"],textarea').blur(function() {
$(this).removeClass("focusField").addClass("idleField");
if ($.trim(this.value) == ''){
this.value = (this.defaultValue ? this.defaultValue : '');
}
});
});
I am looking for a way to exclude those input
fields, which are set readonly
via readonly="readonly"
. I know I should be using .not
(I guess), but I can not figure out how.
I am using this javascript to empty an input/textarea when focussed.
$(document).ready(function() {
$('input[type="text"],textarea').not('[readonly="readonly"]').addClass("idleField");
$('input[type="text"],textarea').focus(function() {
$(this).removeClass("idleField").addClass("focusField");
if (this.value == this.defaultValue){
this.value = '';
}
if(this.value != this.defaultValue){
this.select();
}
});
$('input[type="text"],textarea').blur(function() {
$(this).removeClass("focusField").addClass("idleField");
if ($.trim(this.value) == ''){
this.value = (this.defaultValue ? this.defaultValue : '');
}
});
});
I am looking for a way to exclude those input
fields, which are set readonly
via readonly="readonly"
. I know I should be using .not
(I guess), but I can not figure out how.
1 Answer
Reset to default 11If you want all input elements that are writable (not readonly), you can use the following selector:
$("input:not([readonly])")
The parameter after :not is the selector to match. [readonly] will match anything where readonly is set. Note that the following will not always work:
[readonly="readonly"]
As you could have both of these:
<input readonly type="text">
<input readonly="readonly" type="text">
You can also use the ":input" psuedo-selector instead of "input,textarea". See the documentation here.
本文标签: javascriptExclude an element with a specific attribute from jQuery selectorsStack Overflow
版权声明:本文标题:javascript - Exclude an element with a specific attribute from jQuery selectors - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741518086a2383016.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论