场景:
document.addEventListener('touchmove', function(e) {
e.preventDefault();
}, {
passive: false
});
答案 0 :(得分:1)
在将事件监听器绑定/解除绑定到state
和submitButtonClickHandle
方法时,请使用命名回调函数if(this.state.form.searchValue !== '**some conditions**' &&
this.state.form.circle !== '**some condition**'){
//
alert('You did not meet the search criteria')
} else {
// DO WHAT YOU WANT IF ON THE SUBMIT
alert('everything is fine, here is your result')
}
。
要删除的事件侦听器使用以下命令组合标识 事件类型,事件侦听器函数本身以及各种 可能会影响匹配过程的可选选项;
touchMove
答案 1 :(得分:0)
因此,初始化您的按钮以在单击时将事件侦听器添加到touchmove区域,然后从按钮中删除单击功能并进行设置,以便下一次单击添加删除事件侦听器以删除单击和触摸事件。基本上在按钮和div上切换事件监听器。
//Touchmove action
function preDef(e) {
e.preventDefault();
}
//Add the touchmove action and toggle the button to remove the action
function addE(e) {
e.target.removeEventListener('click', addE, {passive: false});
e.target.addEventListener('click', removeE, {passive: false});
document.addEventListener('touchmove', preDef, {passive: false});
}
//Remove the touchmove action and toggle the button to add the action
function removeE(e) {
e.target.removeEventListener('click', removeE, {passive: false});
e.target.addEventListener('click', addE, {passive: false});
document.removeEventListener('touchmove', preDef, {passive: false});
}
//Initialize the add action
document.getElementById('somebutton').addEventListener('click', addE, {passive: false});