使用动态 asp 值在文本字段内显示文本
我该如何编写,以便在页面加载期间文本显示在文本字段(搜索栏)中?
<输入类型=“文本”id=“addressInput”值=“<%=addressStr%>” onblur="if(this.value=='')this.value='在此处搜索位置';" onfocus="if(this.value=='在此处搜索位置')this.value='';" >>
目前,仅当您单击文本字段时才会显示文本。
How can I write this so the text shows in the text field (search bar) during the page load?
<input type="text" id="addressInput" value="<%=addressStr%>" onblur="if(this.value=='')this.value='Search a location here';" onfocus="if(this.value=='Search a location here')this.value='';" />
At the moment the text only shows when you click in the textfield.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@detonate:您可以将一些相同的逻辑添加到 ASP 值,这样如果
addressStr
为空,它就会显示在此处搜索位置
:@detonate: You could just add some of the same logic to the ASP value so it'll show
Search a location here
ifaddressStr
is blank:看起来您正在尝试为文本框设置水印,对吗?
我将向您推荐一个文本框水印的基本示例,它应该能够为您提供一个示例,并为每个人提供一些通用的代码库供讨论,因为您的帖子中没有包含大量代码:< a href="http://www.codeproject.com/KB/aspnet/WatermarkTextBox.aspx" rel="nofollow">http://www.codeproject.com/KB/aspnet/WatermarkTextBox.aspx
中我将引用他的一个代码块,该代码块与您发布的代码块类似:
虽然我意识到他使用 ASP.NET 而不是 ASP,但我想提请注意他将
放在了这一事实: text
,以便您可以看到上面直接提出的问题的部分答案。编辑:让我再试一次:您会得到这样的结果:
希望该页面上给出的整个示例会对您有所帮助。欢迎提出更多问题。
it looks like you're trying to setup a watermark for a textbox, is that correct?
I'm going to refer you to a basic example of textbox watermarking that should be able to give you an example and give everyone a bit of a common codebase for discussion, since you didn't include a lot of code in your post: http://www.codeproject.com/KB/aspnet/WatermarkTextBox.aspx
In it, I'll reference one of his codeblocks, that is similar to the one you posted:
While I realize he used ASP.NET instead of ASP, I wanted to draw attention to the fact that he put
<textbox>text</textbox>
so that you could see part of the answer to the question you directly asked above.EDIT: Let me try this again: You would have something like this:
Hopefully tho, the whole example given on that page will help you. Feel free to ask more questions.