简体   繁体   中英

HTML: what's the purpose of (difference between) text within <textarea> element compared to (and) that in the placeholder attribute?

If you can use placeholder="visible text", why would one need to have something within the <textarea> tags especially when the user has to manually delete this text? Is there any difference between the 2 code snippets below other than what I mentioned?

<textarea name="textarea" rows="10" cols="50">
Write something here</textarea>

versus

<textarea name="textarea" rows="10" cols="50" 
placeholder="Write something here">
</textarea>

The first code snippet is from: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea

I saw this question[ Html placeholder text in a textarea form ] as related when typing this question but I couldn't find my answer here.

A placeholder is a hint or example to help a user fill in the correct information. You might use it to say, for example, "Your full postal address, including the post code". Be careful not to use it as a substitute for a label element .

The content is a default value. You might use it to put the user's current address so that they can edit it to correct a mistake without having to retype the whole thing.

You might need to have some text between the tags if the user needs to modify it.

For example, if you ask the user for their house number, road name, city and country and display that as an address in a textarea so that they can modify it and add any missing information since that would differ from a user to another.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM