我想在文本字段上显示水印但我不想使用ajax工具包
答案 0 :(得分:3)
试试这个
<input type="text" name="first_name" placeholder="Enter first name">
答案 1 :(得分:2)
<script type = "text/javascript">
var defaultText = "Enter your text here";
function WaterMark(txt, evt)
{
if(txt.value.length == 0 && evt.type == "blur")
{
txt.style.color = "gray";
txt.value = defaultText;
}
if(txt.value == defaultText && evt.type == "focus")
{
txt.style.color = "black";
txt.value="";
}
}
</script>
<asp:TextBox ID="txt_Name" runat="server" Text = "Enter your Name here"
ForeColor = "Gray" onblur = "WaterMark(this, event);"
onfocus = "WaterMark(this, event);">
</asp:TextBox>
或者只是这样做
<input name="q" onfocus="if (this.value=='search') this.value = ''" type="text" value="search">
您还可以添加onblur事件来检查:if(this.value =='')this.value ='search'
当用户在文本框外部单击并且该字段为空时,这将重新打印水印。
这可能对你有所帮助。