问题的核心是:
bind 函数里必须调用 off 函数解绑全局事件,不然下一次打开触发的还是上个元素的事件
解决方案:
将你以前代码的bind函数修改一下
>以下为您以前的代码
- bind: function () {
- var me = this;
- me.$element.on("click", $.proxy(me['_eClick'], me));
- $(document).on("mousedown", "#mykeyboard" + me.count + " li", $.proxy(me['_limousedown'], me));
- $(document).on("mouseup", "#mykeyboard" + me.count + " li", $.proxy(me['_limouseup'], me));
- $(document).on("click", "#mykeyboard" + me.count + " li", $.proxy(me['_liclick'], me));
- },
复制代码 >以下为修改后的代码
- bind: function () {
- var me = this;
- me.$element.off("click");
- me.$element.on("click", $.proxy(me['_eClick'], me));
-
- $(document).off("mousedown", "#mykeyboard" + me.count + " li");
- $(document).off("mouseup", "#mykeyboard" + me.count + " li");
- $(document).off("click", "#mykeyboard" + me.count + " li");
- $(document).on("mousedown", "#mykeyboard" + me.count + " li", $.proxy(me['_limousedown'], me));
- $(document).on("mouseup", "#mykeyboard" + me.count + " li", $.proxy(me['_limouseup'], me));
- $(document).on("click", "#mykeyboard" + me.count + " li", $.proxy(me['_liclick'], me));
- },
复制代码
这个是效果
这个是我修改后的工程文件
如果你觉得我的做法能解决您的问题,请给我素质三连吧(设置最佳答案,点赞,+5分好评)~~
|