页面加载时文本框中的默认文本
一般来说,我看到文本框中填写的任何注册表单,例如在此处输入名字或输入姓氏,我怎样才能这样写。是 JavaScript 吗? 你能告诉我如何写这样的内容帮助我吗谢谢
Generally i saw any registration form the textboxes are filled with for example Enter first name or Enter Last name here like that how can i write like that. Is it javascript?
can u tell me how can i write that like that help me thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据您对 phoenix 帖子的评论,您可以尝试如下操作:
Based on your comments to the post by phoenix you could try something like this:
您想要的是 TextBoxWatermark。 AJAX 控制工具包有一个。
另外,这里是自定义 ASP.NET 文本框水印的示例。
编辑:下面的示例来自上面引用的链接
控制标记:
JS 函数:
代码隐藏:
What you want is a TextBoxWatermark. The AJAX Control Toolkit has one.
Also, here is an example of a custom ASP.NET Textbox Watermark.
EDIT: Example below is from link referenced above
Control Markup:
JS Functions:
Code Behind:
正如您自己所建议的,您可以使用在
onload
事件上调用的 JavaScript,例如:您可以将多个指令分组到一个函数中,然后仅在
onload
上调用该指令。或者您可以直接在输入中设置值:
As you suggested yourself, you could use JavaScript called on the
onload
event, something like:You could group multiple instructions in a function and just call that on
onload
.Or you could just set the value directly in the input:
您必须将文本框的 value 属性设置为所需的文本,例如
当输入接收焦点并且该值是默认值时,然后清除该值。如果用户没有输入任何内容,并且当焦点离开文本框时,会将默认值放回文本框。
另请确保不要使用默认值更新数据库。
You have to set the value property of the textbox to the desired text like
When input receives focus and is the value is the default one then clear the value. And if the user hasn't entered anything and when focus leaves the textbox put the default values back to the textbox.
Also make sure that you don't update database with the default value.