问题
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