我有一个带有 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>
最佳答案
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/