How to set a value and placeholder together for input text?

回眸只為那壹抹淺笑 提交于 2019-12-25 06:37:07

问题


I need to put a hint for a text box.I know it can be done via placeholder , but I also need to set value for the same text box (The initial value should be hidden).Is there any way to that rather than some logic?

This occurred while I am developing a mobile app using html5 and jquery-mobile.I am trying to build a custom hour and minute selector.Insted of html is there any option in jquery-mobile?

Thank you


回答1:


Set the placeholder value via the standard JQM method identified via the JQM docs. Then, have JQuery watch for the user selecting the input field. Then tell JQuery to add a value to the input field.

You could try something like this:

To set an input field with a placeholder:

<input type="text" name="fname" id="input" placeholder="YOUR PLACEHOLDER TEXT">

To add the default value:

$("#input").focus(function() {
     $(this).InnerHTML("ADD DEFAULT VALUE HERE");
 });

JQuery Placeholder info

JQuery Focus info



来源:https://stackoverflow.com/questions/23473602/how-to-set-a-value-and-placeholder-together-for-input-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!