對於文本input
我做的:製作textarea的只讀使用jQuery
$('input[type="text"]').each(function(){
$(this).attr('readonly','readonly');
});
但我應該爲textarea
做什麼,讓它readonly
。
對於文本input
我做的:製作textarea的只讀使用jQuery
$('input[type="text"]').each(function(){
$(this).attr('readonly','readonly');
});
但我應該爲textarea
做什麼,讓它readonly
。
包括在您的選擇(使用multiple/element選擇),就像這樣:
$('input[type="text"], textarea').attr('readonly','readonly');
You can test it here,如果它是你正在做的只有的事情,沒有必要爲.each()
,你可以在所有匹配的元素上調用.attr()
。
試試這個
$("#mytxtarea").attr("disabled", "disabled");
我試過這個。 但如果我重新加載頁面,文本區域不會再次啓用。 – 2012-03-29 07:45:15
在jQuery中的最新版本,將U方法prop
的方法優於使用attr
。
爲了使只讀一個特定的textarea:
$('#mytextarea1').prop('readonly', true);
要使所有文字區域只讀:
$('textarea').prop('readonly', true);
爲了讓所有的 '文本' 字段只讀:
$('input[type=text]').prop('readonly', true);
要使所有'text'字段和textarea只讀:
$('input[type=text],textarea').prop('readonly', true);
也請注意「只讀」,並在外觀方面「禁用」之間的區別:
下面是一個<textarea>
與disabled
設置爲true
:
(看起來不同)
下面是一個<textarea>
與readonly
設置爲true
:
(外觀相同)
您可以編寫
$("textarea").attr("readonly", "readonly");
這將只讀取所有textarea字段。
殘疾人不是隻讀+你實際上混合了已經在這裏幾年的答案。 – ojciecmatki 2014-09-29 13:40:11
是的!你是對的。現在我對我的答案做出改變。感謝您的評論。 – 2014-09-29 13:56:22
這工作..感謝很多... – Hacker 2010-07-21 09:59:45