2011-08-15 9 views
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の属性を設定しなくてもいいが、それが不可能な場合は元に戻す。

ありがとうございました。私がやってしまった何を

答えて

0

た:

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の問題を修正しませんが、彼らは入力タイプの変更をサポートして、少なくともそれは、他のすべての主要なブラウザで動作します。

関連する問題