给出以下的代码展示:

 //绑定 下一页 的点击事件
$("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(){});的区别的更多相关文章

  1. $("#XXX").click()和$("#YYY").on("click","指定的元素",function(){});的区别(jQuery动态绑定事件)

    //绑定 下一页 的点击事件 $("a[aria-label='Next']").click(function(){ $("a[aria-label='Previous' ...

  2. Jquery中$("").事件()和$("").on("事件","指定的元素",function(){});的区别(jQuery动态绑定事件)

    这个是在学习时不懂的问题,记录下来方便查看 转至https://www.cnblogs.com/mr-wuxiansheng/p/7136864.html //绑定 下一页 的点击事件 $(" ...

  3. jQuery的区别:$().click()和$(document).on('click','要选择的元素',function(){})的不同

    jQuery的出现,大大简化了对dom的操作,但是如果不是仔细阅读api和进行操作,就不知道其中最大的优点和使用方式.就拿$().click()和$(document).on('click','要选择 ...

  4. $().click()和$(document).on('click','要选择的元素',function(){})的不同(转https://www.cnblogs.com/sqh17/p/7746418.html)

    $(document).on();用于动态绑定事件 jQuery的出现,大大简化了对dom的操作,但是如果不是仔细阅读api和进行操作,就不知道其中最大的优点和使用方式.就拿$().click()和$ ...

  5. $().click()和$(document).on('click','要选择的元素',function(){})的不同

    1. $(选择器).click(fn) 当选中的选择器被点击时触发回调函数fn.只针对与页面已存在的选择器; 2.$(document).on('click','要选择的元素',function(){ ...

  6. jQuery的on绑定click和直接绑定click区别

    状况之外 在之前的公司并没有遇到这个问题,也就没有深究.直到自己换了现在的公司,刚来第二天就开始写别人写到一半的项目,很无奈,不是原生就是jquery,由于项目急,已经来不及切换框架重新布局,只能继续 ...

  7. 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 ...

  8. hexo next中遇到的bug,引发出的关于jquery中click()函数和on("click",function())的区别

    个人博客:https://mmmmmm.me 源码:https://github.com/dataiyangu/dataiyangu.github.io 背景: 本人在维护博客的时候加入了aplaye ...

  9. $(document).on('click','.classname',function(){}); VS $('.classname').on('click',function(){});

    jquery中用on来绑定事件,经常的写法有$(document).on('click','.classname',function(){});$('.classname').on('click',f ...

随机推荐

  1. c++ vector struct 使用

    1. //test.h #include <string> using namespace std; struct AA { string a1; string a2; string a3 ...

  2. Java for LeetCode 207 Course Schedule【Medium】

    There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...

  3. QT Creator调用动态链接库实例

    #include<iostream> #include <QLibrary> using namespace std; int main() { cout<<&qu ...

  4. 数据结构-链表逆置(c++模板类实现)

    链表结点类模板定义: template <class T> class SingleList; template <class T> class Node { private: ...

  5. 【linux】学习1

    郁闷啊 好多东西要学 下面大概就是鸟哥那本书的第五章内容吧 linux命令: Ctrl + Alt + F1 ~ F6 : 切换终端 ls  -al  ~ :显示主文件夹下的所有隐藏文件 date: ...

  6. spring bean中scope="prototype“的作用

    今天写代码时,遇到个问题,问题大概如下:在写一个新增模块,当各文本框等输入值后,提交存入数据库,跳到其它页面,当再次进入该新增页面时,上次输入的数据还存在. 经过检查发现是,spring配置文件中,配 ...

  7. 在iOS 应用中直接跳转到appstore的方法

    找到应用程序的描述链接,比如:http://itunes.apple.com/gb/app/yi-dong-cai-bian/id391945719?mt=8 然后将 http:// 替换为 itms ...

  8. py随笔

    while true,无限循环 str.isdigit判断是不是数字 +只能在两个两个相同的类型之间执行 iter(i)将i加入迭代器

  9. C 替换字符方法--1

    #include "stdafx.h" //linux 底下要去掉这一行 #include <stdio.h> #include<stdlib.h> #in ...

  10. hdu 2602

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 #include<cstdio> #include<iostream> ...