I have several text boxes with attribute 'readonly'

@Html.TextBoxFor(model => model.ClientNumber, new {@readonly = "readonly", @class ="message-label"})

How can I find all of them using jQuery (to enable similar behavior on keydown event)?

有帮助吗?

解决方案 2

well use attribute seletor..

 $('input[readonly="readonly"]').keydown(function(){
     .....
 });

or just

$('input[readonly]').keydown(function(){..});

其他提示

Try:

 $('input[type="textbox"][readonly]').on('keydown', someHandler);

or shorter:

 $(':text[readonly]').on('keydown', someHandler); //less performance effective than the previous one.

Also if you have a container that holds these and you know the container seelctor then this would be much faster.

 $('containerSelector').find('input[type="textbox"][readonly]').on('keydown', someHandler);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top