替换/重建输入元素和更新PrototypeJS焦点/模糊函数
Replace/Recreate Input Element and Update PrototypeJS Focus/Blur Functions
我有模糊和焦点上的功能,更改密码文本字段从文本更改为密码类型。发生的情况是,我们删除并重新创建它,但原型函数之后不能工作。代码如下:
function focusPass(inputel,inputval) {
if(inputel.value == inputval) {
var newInput = document.createElement('input');
newInput.setAttribute('type','password');
newInput.setAttribute('name',inputel.getAttribute('name'));
newInput.setAttribute('id',inputel.getAttribute('id'));
inputel.parentNode.replaceChild(newInput,inputel);
setTimeout(function() { newInput.focus(); }, 10);
}
}
function blurPass(inputel,inputval) {
if(inputel.value == '') {
var newInput = document.createElement('input');
newInput.setAttribute('type','text');
newInput.setAttribute('name',inputel.getAttribute('name'));
newInput.setAttribute('id',inputel.getAttribute('id'));
newInput.value = inputval;
inputel.parentNode.replaceChild(newInput,inputel);
}
}
if ($('j_password') != undefined) {
blurPass($('j_password'),'password');
$('j_password').observe('blur', function(e) {
blurPass(this,'password');
});
$('j_password').observe('focus', function(e) {
focusPass(this,'password');
});
}
我试着这样做:
document.observe('blur', function(e, el) {
if (el = e.findElement('#j_password')) {
blurPass(this,'password');
}
});
document.observe('focus', function(e, el) {
if (el = e.findElement('#j_password')) {
focusPass(this,'password');
}
});
但这似乎没有任何作用。有人能告诉我如何保持这个函数工作吗?我不喜欢设置属性的onblur和onfocus,但如果它是不可能的,将恢复到那个
谢谢。
我最后做的是:
function focusPass(inputel,inputval) {
if(inputel.value == inputval) {
var ie = getIEVersion();
if (ie > -1 && ie < 9) {
var newInput = document.createElement('input');
newInput.setAttribute('type','password');
newInput.setAttribute('name',inputel.getAttribute('name'));
newInput.setAttribute('id',inputel.getAttribute('id'));
new Insertion.After(inputel, newInput);
inputel.remove();
setTimeout(function() { newInput.focus(); }, 10);
} else {
inputel.setAttribute('type','password');
inputel.value = "";
inputel.focus();
}
}
}
function blurPass(inputel,inputval) {
if(inputel.value == '') {
var ie = getIEVersion();
if (ie > -1 && ie < 9) {
var newInput = document.createElement('input');
newInput.setAttribute('type','text');
newInput.setAttribute('name',inputel.getAttribute('name'));
newInput.setAttribute('id',inputel.getAttribute('id'));
newInput.value = inputval;
new Insertion.After(inputel, newInput);
inputel.remove();
} else {
inputel.setAttribute('type','text');
inputel.value = inputval;
}
}
}
它没有修复IE7和IE8的问题,但至少它可以在所有其他主流浏览器上工作,因为它们支持更改输入类型。
相关文章:
- keyup事件处理程序更改焦点不适用于快速键入
- 单击时将焦点更改为元素
- 后焦点更改为IE 11中的地址栏,而不是转移到表单中的下一个控件
- 在IE9中的输入字段中输入焦点最近按钮
- Javascript游戏输入失去焦点
- ExtJS网格单元格编辑器,防止焦点松动问题
- 检查元素是如何获得焦点的
- angularjs移除焦点上的活动类并添加到下一个项目
- Don'不允许将焦点集中在自动完成的选择上
- 当点击另一件事时,将焦点设置为一件事
- 文本框焦点上的自动完成菜单
- 如何检测哪个窗口是焦点
- 可以't从Youtube IFrame更改焦点
- 在jAlert之后设置焦点
- 在文本区域的焦点上分割渐变
- 使用Redux和React添加焦点更改类
- 在prototypejs中查找对象的类
- iFrames并再次检测焦点
- 如何获得React Native TextInput以在提交后保持焦点
- 替换/重建输入元素和更新PrototypeJS焦点/模糊函数