我想将输入类型文本更改为密码。但它在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);
}
});
});
最佳答案
改变
$('#password1').blur(function () {
到
$('body').on('focusout','#password1',function () {
参见 .on()
W3C 规定 focus
和 blur
事件不冒泡,但 jQuery 定义了跨浏览器的 focusin
和 focusout
冒泡的事件。当 focus
和 blur
用于附加委托(delegate)事件处理程序时,jQuery 映射名称并将它们作为 focusin
和 focusout
分别。为了保持一致和清晰,请使用冒泡事件类型名称。
关于javascript - 当我克隆输入时 onblur 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14498555/