网站首页 > 技术文章 正文
一.JQuery
JQuery 是将 JS 的一些代码块进行封装,方便使用。
1.JQ的引入
(1)link 导入
先进入 https://www.bootcdn.cn/ 网站进行查找,找到后复制到一个 js 中,进行引用。
(2)直接复制标签
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
二.JQ JS 相互转换
1. JQ 获取元素
$('.p1').eq(1).text('今天天气真好')
$('.p1').html('<h>天气真热</h>')
2.JS 转 JQ
$(ap1).text('天好冷')
3. JQ 转 JS
var ap3 = $('.p1')
ap3[0].innerText = '金地是'
ap3.get(1).innerText = '多少金币' //get() 传下标
4. JQ JS 都可用
$('ul li').each(function (){
console.log($(this).text());
// console.log(this.innerText);
console.log($(this).index()); //jq 获取下标
})
三.JQ 操作 HTML 属性
<button>添加</button>
<button>删除</button>
1. 添加 class
//添加class
$("button").eq(0).click(function (){
$("div").addClass("div1")
})
2. 删除 class
(1)removeClass
//删除class
$("button").eq(1).click(function (){
$("div").removeClass("div1")
})
(2)removeAttr
//删除属性和属性值
$("button").eq(1).click(function (){
$("div").removeAttr("class")
3. 修改 class
(1)toggleclass
//无则增 有则增
$("button").eq(0).click(function (){
$("div").toggleClass("div1")
(2)attr
//无则增 有则改
$("button").eq(0).click(function (){
$("div").attr("class","div1")
$("div").attr("class","div2")
})
4.获取 value
$("input").eq(0).val('666');
四.JQ 操作 CSS 样式
1. 获取盒子宽高
(1)获取宽
console.log($("div").width());
(2)获取内边框加宽
$("div").innerWidth()
(3)获取内边框,边框外边距和宽的宽度
$("div").outerWidth()
2. JQ 修改 CSS
// jq修改css
$("div").css("background","blue")
$("div").css({
"background":"pink",
"width":"150px"
})
3.定位元素(父级元素一定要有定位)
$(".div2").position()
4.定位浏览器窗口
$(".div2").offset()
五. JQ 事件
1.单击事件
$("div").click(function (){
console.log(1);
})
2.双击事件
$("div").dblclick(function (){
console.log(2);
})
3.划入事件
$("div").mouseenter(function (){
console.log(3);
})
4.划出事件
$("div").mouseout(function (){
console.log(4);
})
5.划入划出事件
$("div").hover(
function (){
console.log(3);
},function (){
console.log(5);
}
)
6.绑定事件
$("button").click(function (){
$("p").on("click",function (){
$("p").css('background','red')
})
})
7.绑定多个事件
$("p").on({
"mouseenter":function (){
$(this).css('background','yellow')
},
"mouseout":function (){
$(this).css('background','blue')
}
})
8.清除事件
$("button").click(function (){
$("p").off()
})
六. JQ 动画
1. 隐藏
$("button").eq(0).click(function (){
// $("div").hide(1000)
$("div").slideUp(1000)
})
2.显示
$("button").eq(1).click(function (){
$("div").show(1000)
// $("div").slideDown(1000)
})
3.取反
$("button").eq(2).click(function (){
$("div").slideToggle(1000)
// $("div").slideDown(1000)
})
4.淡出事件
$("button").eq(3).click(function (){
$("div").fadeOut(1000)
})
5.淡入事件
$("button").eq(4).click(function (){
$("div").fadeIn(1000)
})
6.淡入淡出取反事件
$("button").eq(5).click(function (){
$("div").fadeToggle(1000)
})
7.动画效果
$("button").eq(6).click(function (){
$("div").delay(100).animate({
"width":"130px",
"height":"130px",
"top":"50px",
"left":"20px",
})
})
8.停止
$("button").eq(7).click(function (){
$("div").stop(1000)
})
附(今日份学习):
猜你喜欢
- 2024-09-11 浅析MySQL Join Reorder算法(mysqlinner join)
- 2024-09-11 js 小函数(js函数总结)
- 2024-09-11 Kubernetes 高性能网络组件 Calico 入门教程
- 2024-09-11 jQuery中的clone妙用(jquery.on)
- 2024-09-11 自定义一个"骚气"的jQuery
- 2024-09-11 前端单元测试以及自动化构建入门(前端单元测试是什么)
- 2024-09-11 Python全栈 Web(jQuery 一条龙服务)
- 2024-09-11 jQuery遍历说、详解与示例的结合,轻松搞定这个遍历!
- 2024-09-11 「clickhouse专栏」对标mongodb存储类JSON数据文档统计分析
- 2024-09-11 jQuery实现简易购物车功能(jquery购物车结算页面)
- 02-21走进git时代, 你该怎么玩?_gits
- 02-21GitHub是什么?它可不仅仅是云中的Git版本控制器
- 02-21Git常用操作总结_git基本用法
- 02-21为什么互联网巨头使用Git而放弃SVN?(含核心命令与原理)
- 02-21Git 高级用法,喜欢就拿去用_git基本用法
- 02-21Git常用命令和Git团队使用规范指南
- 02-21总结几个常用的Git命令的使用方法
- 02-21Git工作原理和常用指令_git原理详解
- 最近发表
- 标签列表
-
- cmd/c (57)
- c++中::是什么意思 (57)
- sqlset (59)
- ps可以打开pdf格式吗 (58)
- phprequire_once (61)
- localstorage.removeitem (74)
- routermode (59)
- vector线程安全吗 (70)
- & (66)
- java (73)
- org.redisson (64)
- log.warn (60)
- cannotinstantiatethetype (62)
- js数组插入 (83)
- resttemplateokhttp (59)
- gormwherein (64)
- linux删除一个文件夹 (65)
- mac安装java (72)
- reader.onload (61)
- outofmemoryerror是什么意思 (64)
- flask文件上传 (63)
- eacces (67)
- 查看mysql是否启动 (70)
- java是值传递还是引用传递 (58)
- 无效的列索引 (74)