0
私は、ぼかしとフォーカスに、テキストからパスワードの種類に変更するためのパスワードテキストフィールドを変更する関数を持っています。何が起こるかは、それを削除して再作成することですが、プロトタイプ関数は後で機能しません。コードは以下の通りである:入力要素の置換/再作成PrototypeJSフォーカス/ぼかし関数
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の属性を設定しなくてもいいが、それが不可能な場合は元に戻す。
ありがとうございました。私がやってしまった何を