2012-01-02 28 views

回答

3

试试这个

<input type="text" name="first_name" placeholder="Enter first name"> 
+0

只适用于HTML5易损浏览器,可能无法与IE – dotNETbeginner 2012-01-02 11:23:47

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事件来检查:如果(THIS.VALUE ==“”)THIS.VALUE =“搜索”

这将重新打印水印时,文本框以外的用户点击,该字段是空的。

这可能会帮助你。

相关问题