占位符的替代方案,以便在Internet Explorer上工作

时间:2016-08-30 08:35:42

标签: javascript html css asp.net internet-explorer

占位符不能在Internet Explorer中使用。

1)当我测试1ts时,它在chrome,firefox中工作,但在Internet Explorer中不起作用。

2)当我测试第二时,它适用于chrome,firefox和Internet Explorer。

我在这里遇到的问题是当我添加(ID =“txtUserID”)这个(2)它在Internet Explorer上不起作用。但我需要(ID =“txtUserID”)这个才能在后端使用它。

对此有何解决方案?

****************1*******************

<asp:TextBox ID="txtUserID" CssClass="form-control" type="text" placeholder="Username " Width="100%" Height="36px" runat="server" Text="adminuser" MaxLength="16" />

****************2*******************

<asp:TextBox CssClass="form-control" Width="100%" Height="36px" MaxLength="16" Text="adminuser" runat="server" value="Username......" placeholder="Username" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"> </asp:TextBox>

1 个答案:

答案 0 :(得分:2)

替代占位符:使用jquery的 onblur 功能,并相应地更改文本框的

&#13;
&#13;
 

   <!DOCTYPE html>
    <html>
    <body>

    Enter your name: <input id="#yourID" type="text" value="placeholder" onfocus="myFunction(this)" onblur="addPlaceHolder(this)">


    <script>
   function myFunction(x) {
    x.value = "";
}
function addPlaceHolder(thisEle){
  
if(thisEle.value=='Place Holder' || thisEle.value=='')
thisEle.value='Place Holder';
}
    </script>

    </body>
    </html>
&#13;
&#13;
&#13;