Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复事件解绑无效的bug #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

qianniuc
Copy link

touchjs v0.2.14调用off函数解除事件绑定,发现无效,遂做此提交,本次提交修复了事件不能解绑以及事件委托不能解绑的问题;本次提交未修改压缩版。

touchjs v0.2.14调用off函数解除事件绑定,发现无效,遂做此提交,本次提交修复了事件不能解绑以及事件委托不能解绑的问题。
@jiayouzl
Copy link

你这个版本也无法解除绑定啊~

if (changan == 1) {
alert('解除绑定了');
touch.off('.content', 'hold');
changan = 0;
}
if (changan == 0) {
touch.on('.content', 'hold', function(ev){
console.log($(this).text());
});
changan = 1;
}
解绑就报错

@luocong123

@qianniuc
Copy link
Author

@jiayouzl 报什么错呢?

@jiayouzl
Copy link

Uncaught TypeError: Cannot read property 'hold' of undefined
@luocong123

2 similar comments
@jiayouzl
Copy link

Uncaught TypeError: Cannot read property 'hold' of undefined
@luocong123

@jiayouzl
Copy link

Uncaught TypeError: Cannot read property 'hold' of undefined
@luocong123

@qianniuc
Copy link
Author

touch.on('.content', 'hold', function(ev){
    console.log('长按');
});
touch.off('.content', 'hold');

你先试试这样看能不能解绑成功

@jiayouzl
Copy link

<title>长按事件</title> <script type="text/javascript" src="./touch-0.2.14.js"></script>
长按我吧
绑定 解绑 <script type="text/javascript"> function bangding() { touch.on('.content', 'hold', function(ev){ console.log(this.innerText); }); } function jiebang() { touch.off('.content', 'hold', function(ev){ console.log('解绑成功!'); }); } </script>

你刚才说的也试了也不行~@luocong123

@qianniuc
Copy link
Author

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        html,body{
            width: 100%;
            height: 100%;
            background: #f5f5f5;
            -webkit-touch-callout:none;
        }
    </style>
</head>
<body class="content">
<script src="touch.js"></script>
<script>
    touch.on('.content', 'hold', function(ev){
        console.log('长按');
        ev.preventDefault();
    });
//    touch.off('.content', 'hold');
</script>
</body>
</html>

我试了试,能解绑啊,把解绑注释掉,长按事件就生效,不注释的话,长按事件就不会生效

@zzhao5
Copy link

zzhao5 commented Dec 19, 2016

function ss(){
    alert(0);
    touch.off('.next-btn',"tap");
}
touch.on('.next-btn',"tap",ss);`

并不能解绑啊。。。是我哪里写错了吗
还有最后的评论里的例子也并不能解绑 @qianniuc


找到原因了,无法解绑是因为没有调用到正确版本的文件。
v0.2.14 2015-11-10 这个版本是可以的,但是在文件列表里找不到,只能在分支里找到

@qianniuc
Copy link
Author

这个项目没人维护了,所以提交代码这么长时间也没人合并过去,所以想解绑的同学就像 @zzhao5 那样自行去拷贝这个版本 v0.2.14 2015-11-10 支持解绑版本 的代码吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants