Javascript 如何在使用TurboLink.visit(路径)时防止冒泡事件
我在自己的项目中使用了aspnetmvcturbolinks,我已经用它重新加载了页面 当用户在输入中添加文本时,Turbolinks.visitpath。但是,当页面更改时,我检查输入的这个keyup事件是否为firemorone,并添加returnfalse但不工作Javascript 如何在使用TurboLink.visit(路径)时防止冒泡事件,javascript,jquery,turbolinks,Javascript,Jquery,Turbolinks,我在自己的项目中使用了aspnetmvcturbolinks,我已经用它重新加载了页面 当用户在输入中添加文本时,Turbolinks.visitpath。但是,当页面更改时,我检查输入的这个keyup事件是否为firemorone,并添加returnfalse但不工作 $(document).on("ready page:load", function() { $('input[name=keyword]').keyup(function (e) { a
$(document).on("ready page:load", function() {
$('input[name=keyword]').keyup(function (e) {
alert();
var $text = $(this).val();
if ($text.length > 1) {
$('html, body').animate({ scrollTop: 0 }, 600, function() {
Turbolinks.visit('@searchUrl' + '?keyword=' + $text);
});
}
if ($text.length == 0) {
Turbolinks.visit('@searchUrl');
}
return false;
});
$(document).on('change', 'select[name="order"]', function() {
Turbolinks.visit('@searchUrl');
});
$(document).on('change', 'select[name="count"]', function() {
Turbolinks.visit('@searchUrl');
});
});
什么是解决方案?
谢谢尝试使用
e.stopPropagation();
而不是
返回false
试试这个
ife.stopPropagation e.stopPropagation
else e.cancelBubble=true;//其中e是事件对象
$('input[name=keyword]').keyup(function (e) {
alert();
var $text = $(this).val();
if ($text.length > 1) {
$('html, body').animate({ scrollTop: 0 }, 600, function() {
Turbolinks.visit('@searchUrl' + '?keyword=' + $text);
});
}
if ($text.length == 0) {
Turbolinks.visit('@searchUrl');
}
if(e.stopPropagation)e.stopPropagation();
else e.cancelBubble=true;
});
使用Turbolinks.Visite'@searchUrl'+'?关键字='+$text时,使用ife.stopPropagatione.stopPropagation;否则e.cancelBubble=true;不可执行问题用e.preventBubble解决;感谢用e.preventBubble解决的问题;谢谢