Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
399 views
in Technique[技术] by (71.8m points)

javascript - 单击时删除输入文本的默认值(Delete default value of an input text on click)

I have an input text :

(我有一个输入文字:)

<input name="Email" type="text" id="Email" value="[email protected]" />

I want to put a default value like "What's your programming question ? be specific."

(我想提出一个默认值,比如“你的编程问题是什么?具体。”)

in StackOverFlow, and when the user click on it the default value disapear.

(在StackOverFlow中,当用户点击它时,默认值为disapear。)

  ask by Wassim AZIRAR translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For future reference, I have to include the HTML5 way to do this.

(为了将来参考,我必须包含HTML5方法来执行此操作。)

<input name="Email" type="text" id="Email" value="[email protected]" placeholder="What's your programming question ? be specific." />

If you have a HTML5 doctype and a HTML5-compliant browser, this will work.

(如果您有HTML5文档类型和HTML5兼容的浏览器,这将有效。)

However, many browsers do not currently support this , so at least Internet Explorer users will not be able to see your placeholder.

(但是, 许多浏览器目前不支持此功能 ,因此至少Internet Explorer用户将无法看到您的占位符。)

However, see http://www.kamikazemusic.com/quick-tips/jquery-html5-placeholder-fix/ ( archive.org version ) for a solution.

(但是,请参阅http://www.kamikazemusic.com/quick-tips/jquery-html5-placeholder-fix/(archive.org 版本 )以获取解决方案。)

Using that, you'll be very modern and standards-compliant, while also providing the functionality to most users.

(使用它,您将非常现代且符合标准,同时还为大多数用户提供功能。)

Also, the provided link is a well-tested and well-developed solution, which should work out of the box.

(此外,提供的链接是经过充分测试和完善的解决方案,应该开箱即用。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...