【问题标题】:onTouchStart event triggering Parent OnClick Event in react jsonTouchStart 事件触发 React js 中的父 OnClick 事件
【发布时间】:2021-10-19 04:56:28
【问题描述】:

嘿,我正在使用带有自定义拖放的 reactjs 创建日历。我在 Ipad 和 Touch 手机上遇到问题。我的代码在桌面上运行完美,但如果我打开 chrome 开发工具并将屏幕分辨率更改为 768px 平板电脑。我的事件也不起作用。请帮助我在父事件和子事件中都使用了cursor:pointere.stopPropagation(),但是没有用。我用 onTouchStart={this.handleTouchStart}

这是我正在使用的代码父事件是

  Sectiondoubletap(e) {
    debugger
    var now = new Date().getTime();
    var timesince = now - this.state.mylatesttap;
    if((timesince < 300) && (timesince > 0)){
 
     // double tap checking
     this._handleDoubleClickSpaltenBody(e)
     console.log("Sectiondoubletap worked")
 
    }
 
    this.state.mylatesttap = new Date().getTime();
 
 }

子事件是

  handleTouchStart(ev) {
    
    
    ev.stopPropagation();

    console.log("handleTouchStart");
    var now = new Date().getTime();
    var timesince = now - this.state.mylatesttap;
    // checking double tap
    if((timesince < 300) && (timesince > 0)){
 
     // double tap checking  
     this._handleDoubleClickItem(ev)
     console.log("Appoinmentdoubletap worked")
 
    }else{
      this.handleDrag(ev);
    }
 
    this.state.mylatesttap = new Date().getTime();

    

   
  }

【问题讨论】:

    标签: javascript jquery reactjs gesture touch-event


    【解决方案1】:

    你有没有尝试改变

    e.stopPropagation()
    

    通过

    e.stopImmediatePropagation()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-11
      • 2016-07-21
      • 1970-01-01
      • 1970-01-01
      • 2016-09-30
      • 2020-02-22
      相关资源
      最近更新 更多