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

2019/6/29 22:28:57

本文主要是介绍jQuery的load()方法及其回调函数用法实例,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

本文实例讲述了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程序设计有所帮助。



这篇关于jQuery的load()方法及其回调函数用法实例的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程