首页 > 语言 > JavaScript > 正文

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

2024-05-06 16:17:35
字体:
来源:转载
供稿:网友

这篇文章主要介绍了jQuery的load()方法及其回调函数用法,实例分析了load方法的简单使用技巧,具有一定参考借鉴价值,需要的朋友可以参考下

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

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

 

 
  1. <!DOCTYPE html> 
  2. <html> 
  3. <head> 
  4. <script src="js/jquery.min.js"> 
  5. </script> 
  6. <script> 
  7. $(document).ready(function(){ 
  8. $("button").click(function(){ 
  9. $("#div1").load("demo_test.txt",function(responseTxt,statusTxt,xhr){ 
  10. if(statusTxt=="success") 
  11. alert("External content loaded successfully!"); 
  12. if(statusTxt=="error") 
  13. alert("Error: "+xhr.status+": "+xhr.statusText); 
  14. }); 
  15. }); 
  16. }); 
  17. </script> 
  18. </head> 
  19. <body> 
  20. <div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div> 
  21. <button>Get External Content</button> 
  22. </body> 
  23. </html> 

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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选