使用动态 asp 值在文本字段内显示文本

发布于 2024-10-06 04:52:34 字数 255 浏览 0 评论 0原文

我该如何编写,以便在页面加载期间文本显示在文本字段(搜索栏)中?

<输入类型=“文本”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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

美人如玉 2024-10-13 04:52:34

@detonate:您可以将一些相同的逻辑添加到 ASP 值,这样如果 addressStr 为空,它就会显示在此处搜索位置

<input type="text" id="addressInput" value="<% If addressStr = "" Then Response.Write "Search a location here" End If %>" onblur="if(this.value=='')this.value='Search a location here';" onfocus="if(this.value=='Search a location here')this.value='';" /> 

@detonate: You could just add some of the same logic to the ASP value so it'll show Search a location here if addressStr is blank:

<input type="text" id="addressInput" value="<% If addressStr = "" Then Response.Write "Search a location here" End If %>" onblur="if(this.value=='')this.value='Search a location here';" onfocus="if(this.value=='Search a location here')this.value='';" /> 
冷了相思 2024-10-13 04:52:34

看起来您正在尝试为文本框设置水印,对吗?

我将向您推荐一个文本框水印的基本示例,它应该能够为您提供一个示例,并为每个人提供一些通用的代码库供讨论,因为您的帖子中没有包含大量代码:< a href="http://www.codeproject.com/KB/aspnet/WatermarkTextBox.aspx" rel="nofollow">http://www.codeproject.com/KB/aspnet/WatermarkTextBox.aspx

中我将引用他的一个代码块,该代码块与您发布的代码块类似:

<td>
    <asp:TextBox ID="txtUserId" runat="server" 
        onfocus="Focus(this.id,'User ID')"
        onblur="Blur(this.id,'User ID')" 
        Width="126px" CssClass="WaterMarkedTextBox">User ID</asp:TextBox>
</td>

虽然我意识到他使用 ASP.NET 而不是 ASP,但我想提请注意他将 放在了这一事实: text,以便您可以看到上面直接提出的问题的部分答案。


编辑:让我再试一次:您会得到这样的结果:

<textbox attributes="" methods="" > 
  <%=addressStr%> 
</textbox>

希望该页面上给出的整个示例会对您有所帮助。欢迎提出更多问题。

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:

<td>
    <asp:TextBox ID="txtUserId" runat="server" 
        onfocus="Focus(this.id,'User ID')"
        onblur="Blur(this.id,'User ID')" 
        Width="126px" CssClass="WaterMarkedTextBox">User ID</asp:TextBox>
</td>

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:

<textbox attributes="" methods="" > 
  <%=addressStr%> 
</textbox>

Hopefully tho, the whole example given on that page will help you. Feel free to ask more questions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文