ygs88
ygs88
  • 发布:2015-03-15 01:41
  • 更新:2015-03-18 18:20
  • 阅读:3231

动态加载的dom添加toggle事件

分类:MUI
mui
document.getElementById("list").innerHTML = str;
mui('.mui-switch').each(function() {  
            var _this = this;  
            _this.addEventListener("toggle", function(event) {  
                console.log("ok");  
                var id = _this.getAttribute("title");  
                if (event.detail.isActive) {  
                    openOrClose(0, id, _this);  
                } else {  
                    openOrClose(1, id, _this);  
                }  
            });  
        });

拼接的字符串列表添加进div , 对列表中的开关按钮无法添加监听事件!

2015-03-15 01:41 负责人:无 分享
已邀请:
DCloud_UNI_FXY

DCloud_UNI_FXY

mui('.mui-switch').each(function() {  
            var _this = this;  
            mui(_this).switch();//手动初始化一下  
            _this.addEventListener("toggle", function(event) {  
                console.log("ok");  
                var id = _this.getAttribute("title");  
                if (event.detail.isActive) {  
                    openOrClose(0, id, _this);  
                } else {  
                    openOrClose(1, id, _this);  
                }  
            });  
        });
太阳光

太阳光

建议用事件委托完成。

ygs88

ygs88 (作者)

上面的回复正确的解决了问题!

该问题目前已经被锁定, 无法添加新回复