分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

对JQuery中Ajax应用与jQuery插件的理解与笔记

发布时间:2023-09-06 01:52责任编辑:董明明关键词:jQueryAjax

Ajax有原生的和封装jQuery版的,感觉JQuery的写法比较简洁明了,不需要去兼容浏览器。

 1 <!DOCTYPE html> 2 <html> 3 ????<head> 4 ????????<meta charset="UTF-8"> 5 ????????<title></title> 6 ????</head> 7 ????<body> 8 ????????<input type="button" value="测试" /> 9 ????</body>10 ????<script type="text/javascript" src="js/jquery-3.3.1.min.js" ></script>11 ????<script type="text/javascript">12 ????????$(function(){13 ????????????$.ajax({14 ????????????????type:"get",//提交数据方式15 ????????????????url:"",//提交路径16 ????????????????async:true//是否异步17 ????????????????data://数据类型18 ????????????});19 ????????});20 ????</script>21 </html>

jQuery插件就更有意思了,是一个比较方便的工具,减少开发项目的周期。

自定义jQuery插件的一种方式 ,这种属于类里面添加方法,给对象调用。还有一种属于类调用,类似于静态方法,

;(function(){ ???????$.fn.extend({ ???????????"color":function(value){ ???????????????return this.css("background-color",value); ???????????} ???????});})(jQuery);
<!DOCTYPE html><html> ???<head> ???????<meta charset="UTF-8"> ???????<title></title> ???</head> ???<body> ???????<input type="text" /> ???????<input type="button" value="变色" /> ???</body> ???<script type="text/javascript" src="js/jquery-3.3.1.min.js" ></script> ???<script type="text/javascript" src="js/jquery.color.js" ></script> ???<script type="text/javascript"> ???????$(function(){ ???????????$("input[type=button]").click(function(){ ???????????????$("input[type=text]").color($("input[type=text]").val()); ???????????}); ???????}); ???</script></html>

在插件内部,this指向的是当前通过选择器获取的jQuery对象,而不像一般的方法那样,例如click()方法,内部的this指向的是DOM元素。

可以通过this.each来遍历所有元素。

对JQuery中Ajax应用与jQuery插件的理解与笔记

原文地址:https://www.cnblogs.com/chyxOne/p/8982534.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved