在IE 8设为默认值的密码输入/场景/股 [英] Set Default Value Of A Password Input / A Scenario / Issue in IE 8

查看:87
本文介绍了在IE 8设为默认值的密码输入/场景/股的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PLZ看到下面的线程:结果
<一href=\"http://stackoverflow.com/questions/4797166/set-default-value-of-a-password-input-so-it-can-be-read\">Set默认值的密码结果
我followd答案1#像这样我的目的:

plz see the below thread :
Set Default Value Of A Password
i followd the answer #1 like this for my purpose :

                <div id="headertxtPassWord-Container" class="header-login-input-Container">
                    <asp:TextBox ID="headertxtPassWord" runat="server" Text="password"
                    onclick="return onclickOfPassWord(this);" onblur="onblurOfPassWord(this);" 
                        CssClass="header-login-input"></asp:TextBox>
                </div>


function onclickOfPassWord(This) {
    if (This.value == 'password') {
        $('#headertxtPassWord-Container').html("<input id='headertxtPassWord' name='headertxtPassWord' type='password' value='' onclick='return onclickOfPassWord(this);' onblur='onblurOfPassWord(this);' class='header-login-input' />");
        $('#headertxtPassWord').focus();
    }
}

function onblurOfPassWord(This) {
    if (This.value == '') {
        $('#headertxtPassWord-Container').html("<input id='headertxtPassWord' name='headertxtPassWord' value='password' onclick='return onclickOfPassWord(this);' onblur='onblurOfPassWord(this);' class='header-login-input' />");
    }
}

但我的codeS已经IE 8和Firefox中的每一件事情是确定的一个问题/如何解决呢?

but my codes has a problem in IE 8 and in firefox every thing is ok / how can fix that ?

问题结果
该文本框从不点击后再次聚焦....结果
我们有任何战利品吗?

problem
that textbox never focus again after click ....
do we have any loot here ?

推荐答案

试试这个code和看看是否有帮助。我试图模仿你的榜样,所以它更有意义。

Try this code and see if it helps. I tried to mimic your example so it makes more sense.

HTML

<div id="headertxtPassWord-Container" class="header-login-input-Container">
    <input id="headertxtPassWord" value="password" class="header-login-input"  />
</div>

JQuery的

$('.header-login-input').bind('click', function() {
    if ($(this).val() === "password")
    {
       this.type = "password";
       $(this).val('');
    }
});

$('.header-login-input').bind('blur', function() {
    if ($(this).val() === "")
    {
       this.type = "text";
       $(this).val('password');
    }
});

另外一个js小提琴手看到一个工作的例子 http://jsfiddle.net/V2Dh5/3/

编辑

这是IE 8

$('.header-login-input').live('click', PopulateElement);

$('.header-login-input').live('blur', function() {
    if ($(this).val() === "")
    {
       $(".header-login-input-Container").html('');
       $(".header-login-input-Container").html("<input id=\"headertxtPassWord\" name=\"headertxtPassWord\" class=\"header-login-input\" value=\"password\" type=\"text\"/>");  
    }
});


function PopulateElement () {
if ($(this).val() === "password")
    {
       $(".header-login-input-Container").html('');
       $(".header-login-input-Container").html("<input id=\"headertxtPassWord\" name=\"headertxtPassWord\" class=\"header-login-input\" type=\"password\"/>");
        setTimeout(function() { $("#headertxtPassWord").focus()}, 10);
    }
}

看JS的小提琴手在 http://jsfiddle.net/V2Dh5/17/

这篇关于在IE 8设为默认值的密码输入/场景/股的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆