可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I'm trying to dynamically update the HTML5 placeholder
attribute of a text field using jQuery.
$("textarea").attr("placeholder", "New placeholder text");
From Firebug, I can observe that the placeholder
attribute is indeed changing. But in the rendered textarea
element, it stays the same. Any suggestions?
回答1:
If you are using Firebug I can assume you are using Firefox, and Firefox doesn't yet support placeholder
attribute in the input fields itself.
Placeholder feature detection
I just tried on Chrome for Mac and it supports placeholder text on textareas (and changes via javascript)
2015 Update: sometimes I gain reputation for this answer, so I want to clarify that this was accepted as correct because at the time Firefox 3.6 didn't support placeholder attribute. Release 4 then added support ("fixed the issue" wouldn't have been fair) so the code of OP works as expected since then.
回答2:
try this :
$('#inputTextID').attr("placeholder","placeholder text");
回答3:
I think you have to do that :
$("textarea").val(''); $("textarea").attr("placeholder", "New placeholder text");
回答4:
回答5:
回答6: