javascript - Angular ui sref 不适用于触摸事件

标签 javascript jquery angularjs angular-ui-router

我有一个带有 ui-sref 属性的链接以及一个 jQuery 触摸事件,但问题是当我单击此元素时,jQuery 处理程序正在运行,但 ui-sref 没有运行。

Jquery:

$('#fa-bar, #mobile-nav li').on('touchstart', function( e ) {
      e.stopPropagation();
      $('#mobile-nav').toggleClass('toggle-mobile-nav');
      $('#mobile-nav').toggleClass('prevent-scroll');
 });

HTML:

 <li ui-sref="state" ui-sref-active="nav-active"><a>Link</a></li>

最佳答案

请参阅docs还有这个example :

However, stopEvent also calls an event object method, event.stopPropagation, which keeps the event from bubbling any further up into the DOM. Note that the table itself has an onclick event handler that ought to display a message when the table is clicked. But the stopEvent method has stopped propagation, and so after the data in the table is updated, the event phase is effectively ended, and an alert box is displayed to confirm this.

这是纯 JavaScript,也适用于 AngularJS。您对 e.stopPropagation() 的调用会阻止 ui-router 获取该事件。如果您想向某些内容添加 URL(这样您仍然可以使用浏览器的“在新选项卡中打开”功能),但希望在正常点击时有不同的行为,这有时会很方便。 p>

关于javascript - Angular ui sref 不适用于触摸事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31266566/

相关文章:

javascript - KendoUI 构建 MVVM 绑定(bind)复选框列表

javascript - 使用两步变量插入 MySQL (Node.js)

javascript - 从<IMG>获取二进制图像内容

javascript - Angular 调用随机服务!为什么?

javascript - Less less.modifyVars 在 Visual Studio 中不起作用?

javascript - 我无法用我的函数隐藏 jquery 自动完成功能

javascript - ajax 调用后图像不显示 [Symfony2]

javascript - jQuery 的 .hide() 和设置 CSS 显示 : none 的区别

javascript - 如果聚合 JavaScript 函数变为负数,则停止更改数字输入

javascript - 基本 Angular 路线不起作用