1. 程式人生 > >監控頁面後退前進,瀏覽器文檔加載事件之pageshow、pagehide

監控頁面後退前進,瀏覽器文檔加載事件之pageshow、pagehide

註冊頁面 位數 brush 加載 rip article 提示 ptp href

輸入密碼後,點擊查看協議,然後返回註冊頁面,密碼輸入欄為空,應該顯示默認提示信息“請設置登錄密碼”,情況如下

技術分享

頁面結構:

<div class="inputwrap">
                        <i class="loginpwd_ico"></i>
                        <input class="jsInptPwd" maxlength="16" type="password" placeholder="" name="loginpwd">
                        <div class="jsPlaceholder input-place">請設置登錄密碼<i>(6-16位數字及字母組成)</i></div>
                    </div>
<div class="protocol-wrap agreement active">
             <span class="icon-cbk"></span>我已閱讀並同意<br><a href="/f/special/member_protocol" id="goLink" class="protocol-link">《會員服務協議》</a>  及  <a href="/f/special/loanAgreement" style="margin-left:0;" id="goLink1" class="protocol-link">《金融服務協議》</a>
            </div>

  

js:

window.addEventListener(‘pageshow‘, function(event) {
                setTimeout(function() {
                    if($(".jsInptPwd").val().trim() !=‘‘){
                        $(".jsPlaceholder").hide();
                    }else{
                        $(".jsPlaceholder").show();
                    }
                }, 101);
});
$(".jsInptPwd").on(‘input propertychange‘,function(){
                
           $(this).val() != ‘‘ ? $(".jsPlaceholder").hide() : $(".jsPlaceholder").show();
 });

註:setTimeout 一定要加,因為有些瀏覽器會延遲(如:QQ瀏覽器)

鏈接:

http://www.cnblogs.com/milo-wjh/p/6811868.html

http://blog.csdn.net/u010154120/article/details/37575041

監控頁面後退前進,瀏覽器文檔加載事件之pageshow、pagehide