jq load方法

  <script type="text/javascript">  
    $(document).ready(function(e){  
          var iframe = document.getElementById("Box");    
        if (iframe.attachEvent) {    
            iframe.attachEvent("onload", function() {    
                //iframe加載完成後你需要進行的操作  
            });    
        } else {    
            iframe.onload = function() {    
                      //iframe加載完成後你需要進行的操作  
            };    
        }    
        //if...else...是一種兼容ie的寫法
    </script>  


語法
$(selector).load(url,data,function(response,status,xhr))

參數	描述
url	必需。規定您需要加載的 URL。
data	可選。規定連同請求發送到服務器的數據。
function(response,status,xhr)	可選。規定 load() 方法完成時運行的回調函數。

額外的參數:
response - 包含來自請求的結果數據
status - 包含請求的狀態("success"、"notmodified"、"error"、"timeout"、"parsererror")
xhr - 包含 XMLHttpRequest 對象
例如:
$("#result").load("ajax/test.html", function() {
  alert("Load was performed.");
});

$("button").click(function(){
  $("#div1").load("demo_test.txt",function(responseTxt,statusTxt,xhr){
    if(statusTxt=="success")
      alert("外部內容加載成功!");
    if(statusTxt=="error")
      alert("Error: "+xhr.status+": "+xhr.statusText);
  });
});

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章