2012-01-02 29 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 =「搜索」

這將重新打印水印時,文本框以外的用戶點擊,該字段是空的。

這可能會幫助你。

相關問題