admin管理员组

文章数量:1336181

I have something like this <input placeholder="something">

The default behavior is the placeholder text disappears when the user begins typing. How can I make it so the placeholder bees the actual content of the field and is editable?

Do I need javascript?

I have something like this <input placeholder="something">

The default behavior is the placeholder text disappears when the user begins typing. How can I make it so the placeholder bees the actual content of the field and is editable?

Do I need javascript?

Share asked May 8, 2014 at 10:58 jopfrejopfre 5033 silver badges12 bronze badges 3
  • If it’s a useful placeholder, it’s hardly a useful default value. What are you really trying to acplish? To set a default (initial) value, just use the good old value attribute. Then a placeholder would probably be just confusing. – Jukka K. Korpela Commented May 8, 2014 at 11:04
  • Why do you want to edit the placeholder value? – Jai Commented May 8, 2014 at 11:09
  • Yep you are right I didn't want a placeholder, I wanted value. Thanks – jopfre Commented May 8, 2014 at 11:31
Add a ment  | 

2 Answers 2

Reset to default 6

Change your placeholder attribute to a value attribute eg:

<input value='foo'/>

This will make foo the default content for the input which will be editable when the user clicks in the field.

you can use value attribute for that:

<input placeholder="something" value="something"/>

using jquery in runtime:

$('inp_selector').val($('inp_selector').attr('placeholder'))

本文标签: javascriptHow can I make the placeholder text of an html input field editableStack Overflow