2

我想将输入类型文本更改为密码。但它在ie8中不起作用。我找到了解决方案;克隆并替换输入,但克隆后 onblur 不起作用。

调试器不会破坏 OnBlur 函数。有人可以给我看看吗?

这是js代码:

$(document).ready(function () {
    var input = document.getElementById("Password");
    var input2 = input.cloneNode(false);
    input2.id = 'password1';
    input2.type = 'password';
    $('#Password').focus(function () {
       input.parentNode.replaceChild(input2, input);
       input2.focus();
    });
    $('#password1').blur(function () {
        if ($(this).val() == '' || $(this).val() == Passwordtxt) {
            document.getElementById("password1").setAttribute("type", "text");
            $(this).val(Passwordtxt);
        }
    });
});
4

2 回答 2

0

改变

$('#password1').blur(function () {

$('body').on('focusout','#password1',function () {

.on()

和事件由 W3C 指定为不冒泡,但 jQuery 定义了跨浏览器和focus冒泡的事件。当和用于附加委托事件处理程序时,jQuery 映射名称并将它们分别作为和传递。为了一致性和清晰性,使用冒泡事件类型名称。blurfocusinfocusoutfocusblurfocusinfocusout

于 2013-01-24T10:57:46.113 回答
-2

使用on事件委托

试试这个

$(document).on('blur','#password1',function () {...

document最好用最接近的元素替换

于 2013-01-24T10:05:20.330 回答