ie9的placeholder不顯示的解決辦法(包含多個密碼框)


 
        
function isPlaceholder(){
    var input = document.createElement('input');
    return 'placeholder' in input;
}
if (!isPlaceholder()) {//不支持placeholder 用jquery來完成
    $(document).ready(function() {
        if(!isPlaceholder()){
            $("input").not("input[type='password']").each(//把input綁定事件 排除password框
                    function(){
                        if($(this).val()=="" && $(this).attr("placeholder")!=""){
                            $(this).val($(this).attr("placeholder"));
                            $(this).focus(function(){
                                if($(this).val()==$(this).attr("placeholder")) $(this).val("");
                            });
                            $(this).blur(function(){
                                if($(this).val()=="") $(this).val($(this).attr("placeholder"));
                            });
                        }
                    });
            //對password框的特殊處理1.創建一個text框 2獲取焦點和失去焦點的時候切換
            $("input[type='password']").each(
                    function() {
                        var pwdField    = $(this);
                        var pwdVal      = pwdField.attr('placeholder');
                        pwdField.after('<input  class="login-input" type="text" value='+pwdVal+' autocomplete="off" />');
                        var pwdPlaceholder = $(this).siblings('.login-input');
                        pwdPlaceholder.show();
                        pwdField.hide();

                        pwdPlaceholder.focus(function(){
                            pwdPlaceholder.hide();
                            pwdField.show();
                            pwdField.focus();
                        });

                        pwdField.blur(function(){
                            if(pwdField.val() == '') {
                                pwdPlaceholder.show();
                                pwdField.hide();
                            }
                        });
                    })
        }
    });
}


免責聲明!

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



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