2015-08-21 45 views

回答

4

您剛從迭代函數返回,而不是從beforeunload處理程序返回。 jQuery用函數的返回值做的唯一事情是測試它是否爲false,並停止迭代。它不會從包含函數返回。

window.onbeforeunload = function(e) { 
    var return_val = null; 
    $('#wrapper>div').each(function(k,v) { 
     if($(this).text() == 's') { 
      return_val = 'aaaa'; 
      return false; // End the loop 
     } 
    }); 
    return return_val; 
}; 
1
window.onbeforeunload = function(e) { 
    $('#wrapper>div').each(function(k,v) { 
     if($(this).text() == 's') { 
      $(this).text('aaaa'); 
     } 
    }); 
} 
+1

這對OP的問題「確認彈出窗口沒有出現」有什麼幫助? – nnnnnn