Javascript IE中的ASP.Net占位符问题
我正在尝试使用asp.net创建一个登录页面,并在每个文本框上放置一个占位符。它在chrome和Firefox中运行良好,但在IE8中它不显示任何占位符。当我输入javascript代码时,它只在我的用户名文本框中起作用,而在密码文本框中它什么也不显示。 这里有人能帮我吗?请提前谢谢你 这是我到目前为止得到的Javascript IE中的ASP.Net占位符问题,javascript,html,asp.net,vb.net,Javascript,Html,Asp.net,Vb.net,我正在尝试使用asp.net创建一个登录页面,并在每个文本框上放置一个占位符。它在chrome和Firefox中运行良好,但在IE8中它不显示任何占位符。当我输入javascript代码时,它只在我的用户名文本框中起作用,而在密码文本框中它什么也不显示。 这里有人能帮我吗?请提前谢谢你 这是我到目前为止得到的 <asp:TextBox ID="txtuser" runat="server" MaxLength="20" placeholder = "username"></as
<asp:TextBox ID="txtuser" runat="server" MaxLength="20" placeholder = "username"></asp:TextBox>
<asp:TextBox ID="txtpass" runat="server" MaxLength="25" class = "password-input" TextMode = "Password" placeholder = "Password"></asp:TextBox>
可以发布JSFIDLE吗?谢谢你。@carol。。不,我不能在JSFIDLE上发布。主要问题是密码的占位符在ie上不起作用,但在其他浏览器上效果很好。试试这个:它不起作用。。在asp.net中,需要使用textmode=密码将输入值转换为如下内容。。1234将是****。另一个答案?非常感谢你。
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script type="text/javascript">
/* <![CDATA[ */
$(function() {
var input = document.createElement("input");
if (('placeholder' in input) == false) {
$('[placeholder]').focus(function() {
var i = $(this);
if (i.val() == i.attr('placeholder')) {
i.val('').removeClass('placeholder');
if (i.hasClass('password')) {
i.removeClass('password');
this.type = 'password';
}
}
}).blur(function() {
var i = $(this);
if (i.val() == '' || i.val() == i.attr('placeholder')) {
if (this.type == 'password') {
i.addClass('password');
this.type = 'text';
}
i.addClass('placeholder').val(i.attr('placeholder'));
}
}).blur().parents('form').submit(function() {
$(this).find('[placeholder]').each(function() {
var i = $(this);
if (i.val() == i.attr('placeholder'))
i.val('');
})
});
}
});
/* ]]> */