jquery事件
来源:互联网 发布:mac上传图片 编辑:程序博客网 时间:2024/05/23 12:31
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
</style>
</head>
<body>
<div >来啊来啊~点我啊</div>
<div >来啊来啊~点我啊1</div><div >来啊来啊~点我啊2</div>
</body>
<script src="js/jquery-3.2.1.min.js" ></script>
<script type="text/javascript">
console.log($('div')[0]);
//jq对象中的第一个元素是原生的js节点(元素)
//如果有几个元素 前几个就分别是原生的js节点
//把jq对象看做一个数组 例如:有三个div 那么数组的前三个对象就是你的三个div,后面是jq封装的方法
$('div')[0].onclick=function(){
alert('你还真点我!');
}
//JQ绑定事件 on('事件名',function(){执行的代码});
//jquery自动有循环绑定效果
//jquery 中的$(this) 相当与原生的方法中的this
//.index获取索引
//.eq(索引) 获取相应的jq对象
$('div').on('click',function(){
$('div').css({'backgroundColor':'white'});
$(this).css({'backgroundColor':'yellow'});
console.log($(this).index());
});
//清除事件.off()
//$('div').off('mouseover');
</script>
</html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
</style>
</head>
<body>
<div >来啊来啊~点我啊</div>
<div >来啊来啊~点我啊1</div><div >来啊来啊~点我啊2</div>
</body>
<script src="js/jquery-3.2.1.min.js" ></script>
<script type="text/javascript">
console.log($('div')[0]);
//jq对象中的第一个元素是原生的js节点(元素)
//如果有几个元素 前几个就分别是原生的js节点
//把jq对象看做一个数组 例如:有三个div 那么数组的前三个对象就是你的三个div,后面是jq封装的方法
$('div')[0].onclick=function(){
alert('你还真点我!');
}
//JQ绑定事件 on('事件名',function(){执行的代码});
//jquery自动有循环绑定效果
//jquery 中的$(this) 相当与原生的方法中的this
//.index获取索引
//.eq(索引) 获取相应的jq对象
$('div').on('click',function(){
$('div').css({'backgroundColor':'white'});
$(this).css({'backgroundColor':'yellow'});
console.log($(this).index());
});
//清除事件.off()
//$('div').off('mouseover');
</script>
</html>
阅读全文
0 0
- jQuery事件
- jquery事件
- JQuery事件
- JQuery事件
- jQuery事件
- jquery事件
- jQuery事件
- JQuery事件
- jquery 事件
- jquery事件
- jquery事件
- jQuery事件
- jQuery事件
- jQuery 事件
- jquery 事件
- jquery 事件
- JQuery事件
- jQuery 事件
- 应用层数据传递之http协议
- 爬虫涉及若干问题
- Ubuntu 火狐浏览器中,鼠标选择文字被删除的解决办法
- 叽里呱啦。
- Qt学习之路(26): 反走样
- jquery事件
- (Basic algorithm学习笔记)《基础算法一》- 排序
- splay树模板
- 求两个字符串的公共连续子序列
- RxJAVA操作符
- python 包和模块 等于号(==)和is的区别与联系 对象的拷贝(copy)
- JQ分页
- sqlite3中,blob字段的读取和写入
- vue+vuex+localStorage实现记事本