如何使用JQuery在网页上查找所有只读文本框

时间:2022-10-31 13:07:31

I have been asked to identify all read only text boxes in an Asp.Net page and assign a particular style. I'm pretty sure I could iterate over all of the inputs to see if they were inputs that were text boxes with the readonly attribute but I just KNOW there's a one liner.

我被要求在Asp.Net页面中识别所有只读文本框并指定特定样式。我很确定我可以迭代所有输入,看看它们是否是带有readonly属性的文本框的输入,但我只知道有一个单行。

Any thoughts?

4 个解决方案

#1


20  

Is this what you're looking for?

这是你在找什么?

$('input[type=text][readonly]')

http://jsfiddle.net/rZvnm/

#2


6  

Technically, this should be enough to limit to readonly text inputs:

从技术上讲,这应该足以限制只读文本输入:

$(':text[readonly]'); // equivalent to $('*:text[readonly]')

But if it was me I like to be a little more specific and include a tag (jQuery recommends it as well):

但如果是我,我想更具体一点,并包含一个标签(jQuery推荐它):

$('input:text[readonly]');

And also according to the jQuery documentation, it is faster in modern browsers to use the type attribute selector instead of :text:

而且根据jQuery文档,在现代浏览器中使用type属性选择器而不是:text更快:

$('input[type=text][readonly]');

I use [readonly] instead of [readonly=readonly] to merely test for the presence of the attribute, not what its value is.

我使用[readonly]而不是[readonly = readonly]来仅仅测试属性的存在,而不是它的值是什么。

#3


4  

$.extend($.expr[':'],{
    readonly: function(obj) {
        return $(obj).is('[readonly]');
    }
});

 $('input:text:readonly');

it is the best way I found.

这是我找到的最好的方式。

#4


2  

try the below

尝试以下

$('input[Type="text"]&[readonly="readonly"]')

#1


20  

Is this what you're looking for?

这是你在找什么?

$('input[type=text][readonly]')

http://jsfiddle.net/rZvnm/

#2


6  

Technically, this should be enough to limit to readonly text inputs:

从技术上讲,这应该足以限制只读文本输入:

$(':text[readonly]'); // equivalent to $('*:text[readonly]')

But if it was me I like to be a little more specific and include a tag (jQuery recommends it as well):

但如果是我,我想更具体一点,并包含一个标签(jQuery推荐它):

$('input:text[readonly]');

And also according to the jQuery documentation, it is faster in modern browsers to use the type attribute selector instead of :text:

而且根据jQuery文档,在现代浏览器中使用type属性选择器而不是:text更快:

$('input[type=text][readonly]');

I use [readonly] instead of [readonly=readonly] to merely test for the presence of the attribute, not what its value is.

我使用[readonly]而不是[readonly = readonly]来仅仅测试属性的存在,而不是它的值是什么。

#3


4  

$.extend($.expr[':'],{
    readonly: function(obj) {
        return $(obj).is('[readonly]');
    }
});

 $('input:text:readonly');

it is the best way I found.

这是我找到的最好的方式。

#4


2  

try the below

尝试以下

$('input[Type="text"]&[readonly="readonly"]')