替代占位符,以便在Internet explorer中工作

alternative for placeholder in order to work at internet explorer

本文关键字:Internet explorer 工作 占位符      更新时间:2023-09-26

占位符不能在ie浏览器中使用。

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>

替代占位符:使用jquery的onblur函数,相应改变文本框的值

 
   <!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>