代碼如下:
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中均能正常使用。
