【jQuery 区别】.click()和$(document).on("click","指定的元素",function(){});的区别
给出以下的代码展示:
//绑定 下一页 的点击事件
$("a[aria-label='Next']").click(function(){
$("a[aria-label='Previous']").show();
if(page.pageNo == page.totalPage - 1){
$("a[aria-label='Next']").hide();
}else{
$("a[aria-label='Next']").show();
}
page.pageNo++;
page.pageSet(bindData , page);
}); //上面的.click()绑定点击事件 和 下面的 $(document).on("click",".pagination li:gt(0):not(:last)",function(){});的区别在于:
//.click只能为页面现有的元素绑定点击事件,如果是动态生成的新的元素,是没有事件的
//而$(document).on("click","指定的元素",function(){});方法则是将指定的事件绑定在document上,而新产生的元素如果符合指定的元素,那就触发此事件 //为动态生成的 页码按钮 添加 点击事件
$(document).on("click",".pagination li:gt(0):not(:last)",function(){
page.pageNo = $(this).text();
$("a[aria-label='Previous']").show();
$("a[aria-label='Next']").show();
if(page.pageNo == "1"){
$("a[aria-label='Previous']").hide();
}
if(page.pageNo == page.totalPage){
$("a[aria-label='Next']").hide();
} page.pageSet(bindData , page);
});
上面的.click()绑定点击事件 和 下面的 $(document).on("click",".pagination li:gt(0):not(:last)",function(){});的区别在于:
1》》.click只能为页面现有的元素绑定点击事件,如果是动态生成的新的元素,是没有事件的
2》》而$(document).on("click","指定的元素",function(){});方法则是将指定的事件绑定在document上,而新产生的元素如果符合指定的元素,那就触发此事件
【jQuery 区别】.click()和$(document).on("click","指定的元素",function(){});的区别的更多相关文章
- $("#XXX").click()和$("#YYY").on("click","指定的元素",function(){});的区别(jQuery动态绑定事件)
//绑定 下一页 的点击事件 $("a[aria-label='Next']").click(function(){ $("a[aria-label='Previous' ...
- Jquery中$("").事件()和$("").on("事件","指定的元素",function(){});的区别(jQuery动态绑定事件)
这个是在学习时不懂的问题,记录下来方便查看 转至https://www.cnblogs.com/mr-wuxiansheng/p/7136864.html //绑定 下一页 的点击事件 $(" ...
- jQuery的区别:$().click()和$(document).on('click','要选择的元素',function(){})的不同
jQuery的出现,大大简化了对dom的操作,但是如果不是仔细阅读api和进行操作,就不知道其中最大的优点和使用方式.就拿$().click()和$(document).on('click','要选择 ...
- $().click()和$(document).on('click','要选择的元素',function(){})的不同(转https://www.cnblogs.com/sqh17/p/7746418.html)
$(document).on();用于动态绑定事件 jQuery的出现,大大简化了对dom的操作,但是如果不是仔细阅读api和进行操作,就不知道其中最大的优点和使用方式.就拿$().click()和$ ...
- $().click()和$(document).on('click','要选择的元素',function(){})的不同
1. $(选择器).click(fn) 当选中的选择器被点击时触发回调函数fn.只针对与页面已存在的选择器; 2.$(document).on('click','要选择的元素',function(){ ...
- jQuery的on绑定click和直接绑定click区别
状况之外 在之前的公司并没有遇到这个问题,也就没有深究.直到自己换了现在的公司,刚来第二天就开始写别人写到一半的项目,很无奈,不是原生就是jquery,由于项目急,已经来不及切换框架重新布局,只能继续 ...
- jquery bind event, use on. $(document).on("click","#a",function(){alert(1)}) [#document]
$(document).on("click","#a",function(){alert(1)}) [#document] as a replacement o ...
- hexo next中遇到的bug,引发出的关于jquery中click()函数和on("click",function())的区别
个人博客:https://mmmmmm.me 源码:https://github.com/dataiyangu/dataiyangu.github.io 背景: 本人在维护博客的时候加入了aplaye ...
- $(document).on('click','.classname',function(){}); VS $('.classname').on('click',function(){});
jquery中用on来绑定事件,经常的写法有$(document).on('click','.classname',function(){});$('.classname').on('click',f ...
随机推荐
- linux (RHEL) 添加和删除用户
linux添加新用户使用 useradd -----create a new user or update default new user information 删除用户使用userdel -- ...
- ffmpeg-20160517-git-bin-v2
ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 S 下一帧 [ -2秒 ] +2秒 ; -1秒 ' +1秒 下一个帧 -> -5秒 f ...
- intel 面试总结
昨天面了intel的Android部门,基无意外,面试的效果不是很好,很多问题没有回答上来,看来如果要进intel这种大公司光靠SJTU光环是远远不够的,必须要有真才实学.面试的还是一位交大学长,本科 ...
- Match:DNA repair(POJ 3691)
基因修复 题目大意:给定一些坏串,再给你一个字符串,要你修复这个字符串(AGTC随便换),使之不含任何坏串,求修复所需要的最小步数. 这一题也是和之前的那个1625的思想是一样的,通过特殊的trie树 ...
- func 和 actin 委托的区别
一.[action<>]指定那些只有输入参数,没有返回值的委托 1.1定义一个委托: 比如,我们原来写委托: public delegate void myDelegate(string ...
- [Android Pro] Android 6.0 Root
reference : http://bbs.gfan.com/android-8001827-1-1.html 2. 刷机和刷入recovery 建议参考 置顶教程: [15年3月31日更新]Nex ...
- 解决spring+shiro cacheManager 登录报错
一.项目启动,登录报错 org.springframework.beans.factory.BeanCreationException: Error creating bean with name ' ...
- iOS小技巧总结,绝对有你想要的
原文链接 在这里总结一些iOS开发中的小技巧,能大大方便我们的开发,持续更新. UITableView的Group样式下顶部空白处理 //分组列表头部空白处理 UIView *view = [[UIV ...
- 51nod1057(python2计算n!)
题目链接:www.51nod.com/onlineJudge/questionCode.html#!problemId=1057 思路:直接for循环呗- 代码: n = int( raw_input ...
- Jquery.Datatables 基本创建方法
基本创建 <!--定义操作列按钮模板--> <script id="tpl" type="text/x-handlebars-template" ...