Changing the “placeholder” attribute of HTML5 input elements dynamically using Javascript

后端 未结 6 1134
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-15 16:03

I\'m trying to dynamically update the HTML5 placeholder attribute of a text field using jQuery.

$(\"textarea\").attr(\"placeholder\", \"New plac         


        
6条回答
  •  自闭症患者
    2020-12-15 16:28

    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.

提交回复
热议问题