jQuery的load()方法及其回调函数用法实例

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

jQuery的load()方法及其回调函数用法实例

上大王   2020-05-13 我要评论

本文实例讲述了jQuery的load()方法及其回调函数用法。分享给大家供大家参考。具体如下:

下面的js代码演示了jQuery的load()方法的使用,并演示了带回调函数(callback)的load方法的使用

<!DOCTYPE html>
<html>
<head>
<script src="js/jquery.min.js">
</script>
<script>
$(document).ready(function(){
 $("button").click(function(){
  $("#div1").load("demo_test.txt",function(responseTxt,statusTxt,xhr){
   if(statusTxt=="success")
    alert("External content loaded successfully!");
   if(statusTxt=="error")
    alert("Error: "+xhr.status+": "+xhr.statusText);
  });
 });
});
</script>
</head>
<body>
<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
<button>Get External Content</button>
</body>
</html>

希望本文所述对大家的jQuery程序设计有所帮助。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们