JQuery中如何動態修改input的type屬性


代碼如下:

 1     jQuery(".member_id").focus(function() { 
 2       jQuery(this).val('');
 3     }).blur(function() { 
 4         
 5       if(jQuery(this).val() == "") { jQuery(this).val("賬號"); }
 6     });
 7 
 8     jQuery(".member_passwd").focus(function() { 
 9       jQuery(this).val('');
10      document.getElementById("member_passwd").type="password";
11        //jQuery(this).attr('type','password');
12     }).blur(function() { 
13         
14       if(jQuery(this).val() == "") { jQuery(this).val("密碼");  document.getElementById("member_passwd").type="text"; }
15     });
16 
17 
18 }); 

 

以上代碼注釋部分會報錯,提示“type property can't be changed ”,初步結論JQuery中的attr()方法不可以修改input的type屬性。

 

此段代碼在IE,chrome、FireFox中均能正常使用。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM