jquery事件委托方法有:1、blind()方法,主要用于给选择到的元素进行事件绑定;2、live()方法,向当前或未来的匹配元素添加一个或多个事件处理器;3、delegate()方法;4、on()方法,用于将监听事件绑定到就近父级元素。
本教程操作环境:windows7系统、jquery1.10.2版本、Dell G3电脑。
什么是事件委托?
子元素的事件委托给父元素,而不是分给子元素自己去绑定事件,然后触发事件的时候找到对应的event.target
是指利用事件冒泡,只指定一个事件处理程序,来管理某一类型的所有事件
为什么要用事件委托?
因为在js中添加到页面的事件处理程序个数会影响到页面的整体运行性能
其次对列表逐个添加事件处理程序太过于麻烦,所以,事件委托极大地提高了页面运行的性能
通过for循环给ul底下的li遍历绑定事件,看似没有问题但实际非常影响页面的运行性能
此时,就用到冒泡模式的事件委托来解决
然而,有会想到绑定给ul的事件,实现后岂不是每个li都会受影响吗?
出此案了新概念:事件源:不管事件绑定在那个元素中,都指的是实际触发事件的内个目标
event.target
eg:ul.onclick=function(event){}
简单点就是 减少DOM访问,减少内存,提高页面的运行性能
jquery事件委托方法有哪些
1、blind
定义和用法:主要用于给选择到的元素进行事件绑定
语法:
blind("事件类型",data,function(){ }); //data是传入函数的参数用event.data获取(平时用的.click()等都是其简化用法)
特点;适用于静态页面,只能给调用它时已存在的元素绑定,不能给未来新增的元素绑定
当页面加载完时,才进行blind;
2、live(1.7以后不支持)
定义:向当前或未来的匹配元素添加一个或多个事件处理器;
语法:
live("事件类型",data, 函数名);//data可选
特点:live并没有将事件绑定到自身(this)上,而是绑定到this.context上
正是利用了事件委托机制完成事件的监听处理,把节点的处理委托给 document
新添加的元素不必再绑定一次监听器,可多事件处理
只能放在直接选择的元素的后面
3、delegate
定义:将监听事件绑定到就近父级元素,因为事件可以更快的冒泡上去
语法:
delegate(selector,type,[data],fn)
特点:更精确的小范围使用事件代理,性能优于.live()。可以用在动态添加的元素上。
("父级选择器").delegate(".a","click",function())//表示:.a的事件通过父级元素进行委托,(this)获取的是触发事件的子元素
4、on
定义;将监听事件绑定到就近父级元素
语法:
on(type, 选择器,方法)
特点:给父元素底下新添加的标签也可以用监听事件
也支持多时事件处理
【推荐学习:jQuery视频教程、web前端视频】
以上是jquery事件委托方法有哪些的详细内容。更多信息请关注PHP中文网其他相关文章!

Include:1)AsteeplearningCurvedUetoItsVasteCosystem,2)SeochallengesWithClient-SiderEndering,3)潜在的PersperformanceissuesInsuesInlArgeApplications,4)ComplexStateStateManagementAsappsgrow和5)TheneedtokeEedtokeEedtokeEppwithitsrapideDrapidevoltolution.thereedtokeEppectortorservolution.thereedthersrapidevolution.ththesefactorsshesssheou

reactischallengingforbeginnersduetoitssteplearningcurveandparadigmshifttocoment oparchitecent.1)startwithofficialdocumentationforasolidFoundation.2)了解jsxandhowtoembedjavascriptwithinit.3)

ThecorechallengeingeneratingstableanduniquekeysfordynamiclistsinReactisensuringconsistentidentifiersacrossre-rendersforefficientDOMupdates.1)Usenaturalkeyswhenpossible,astheyarereliableifuniqueandstable.2)Generatesynthetickeysbasedonmultipleattribute

javascriptfatigueinrectismanagbaiblewithstrategiesLike just just in-timelearninganning and CuratedInformationsources.1)学习whatyouneedwhenyouneedit

totlecteactComponents通过theusestatehook,使用jestandReaCtteTingLibraryToSigulation Interactions andverifyStatAtaTeChangesInTheUI.1)renderthecomponentAndComponentAndComponentAndCheckInitialState.2)模拟useclicklicksorformsormissionsions.3)

KeysinreactarecrucialforopTimizingPerformanceByingIneFefitedListupDates.1)useKeyStoIndentifyAndTrackListelements.2)避免使用ArrayIndicesasKeystopreventperformansissues.3)ChooSestableIdentifierslikeIdentifierSlikeItem.idtomaintainAinainCommaintOnconMaintOmentStateAteanDimpperperFermerfermperfermerformperfermerformfermerformfermerformfermerment.ChosestopReventPerformissues.3)

ReactKeySareUniqueIdentifiers usedwhenrenderingListstoimprovereConciliation效率。1)heelPreactrackChangesInListItems,2)使用StableanDuniqueIdentifiersLikeItifiersLikeItemidSisRecumended,3)避免使用ArrayIndicesaskeyindicesaskeystopreventopReventOpReventSissUseSuseSuseWithReRefers和4)

独特的keysarecrucialinreactforoptimizingRendering和MaintainingComponentStateTegrity.1)useanaturalAlaluniqueIdentifierFromyourDataiFabable.2)ifnonaturalalientedifierexistsistsists,generateauniqueKeyniqueKeyKeyLiquekeyperaliqeyAliqueLiqueAlighatiSaliqueLiberaryLlikikeuuId.3)deversearrayIndiceSaskeyseSecialIndiceSeasseAsialIndiceAseAsialIndiceAsiall


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能