framework7-cn

Open full view…

页面上无限滚动新增的元素如何添加点击事件

luohuidew
Fri, 05 Jun 2015 12:21:44 GMT

页面上无限滚动新增的元素有收藏按钮,点击背景切换,但进入其他页面再返回后事件不起作用,怎么办?谢谢大神们哦!!!!!!!

elderjames
Wed, 10 Jun 2015 14:20:48 GMT

在每次加载都写一遍事件绑定,因为新增加的元素没有绑定事件,就不会触发 。

余恒竹
Thu, 18 Jun 2015 03:58:10 GMT

用事件代理啊

余恒竹
Thu, 18 Jun 2015 03:59:18 GMT

用事件委托 $$('document').on('click','.btn',function(){ //即便是后加的DOM元素,也是有事件的 })

luohuidew
Wed, 24 Jun 2015 03:10:54 GMT

$$('document').on('click','.Schooldu',function(){ var id = $$(this).data('Schoolid'); $.get('../../wapserver/web/index.php?r=v1/school/view',{'id':id},func tion (data) { var tishi=eval('(' + data + ')'); school_xq=tishi.item.info.description; collect=tishi.item.collect; tishi.item.info.description=school_xq.substring(0,100); if(tishi.item.info.offerScholarship=="0"){tishi.item.info.offerScholar ship="否";} else{ tishi.item.info.offerScholarship="是"; } if(tishi.item.info.offerDormitory =="0"){tishi.item.info.offerDormitory ="否";} else{ tishi.item.info.offerDormitory ="是"; } if(tishi.status=="success"){ mainView.router.load({ url: 'list_xq.html', context:tishi.item, }) schoolshenlist = Template7.templates.school_xqlist(tishi.item); schoolshensuo = Template7.templates.schoolshensuo(tishi.item); } }); }); 没有反应呢?为什么不对吧??

xiefangzhenz
Mon, 07 Nov 2016 02:52:16 GMT

@余恒竹 问题解决了,多谢