如何为输入文本一起设置值和占位符? [英] How to set a value and placeholder together for input text?

查看:162
本文介绍了如何为输入文本一起设置值和占位符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为文本框添加提示,我知道可以通过占位符来完成,但是我还需要为同一文本框设置值(初始值应该被隐藏).而不是某些逻辑?

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?

这是在我使用html5和jquery-mobile开发移动应用程序时发生的.我正在尝试构建自定义的小时和分钟选择器.插入html的jquery-mobile中是否有任何选项?

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?

谢谢

推荐答案

通过通过JQM文档标识的标准JQM方法设置占位符值.然后,让JQuery监视用户选择输入字段.然后告诉JQuery在输入字段中添加一个值.

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">

要添加默认值:

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

jQuery占位符信息

JQuery焦点信息

这篇关于如何为输入文本一起设置值和占位符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆