gpt4 book ai didi

ruby-on-rails - rails link_to with remote => true and jquery on click

转载 作者:行者123 更新时间:2023-12-04 05:57:47 24 4
gpt4 key购买 nike

我有一个简单的问题。我像这样使用rails link_to:

link_to 'sometxt', some_path(item), :class=>'fancybox button-click', :remote => true

我的问题 - 将 jQuery 放在此链接的点击事件上是否正确?
$('.button-click').on('click',function(){
//some action
});

或者在一个链接的点击事件上使用带有远程和 jQuery 的 link_to 不是一个好的解决方案?

我想要的是在用户单击链接时附加加载 gif,而 fancybox showLoading 对我不起作用,所以我正在尝试其他方式来放置预加载器。

最佳答案

好问题!!

我不确定是否要覆盖 click事件(我确定绑定(bind)两次就可以了,但我没有任何引用资料)

--

Ajax

关于调用 preloader ,你会想要使用 one of the ajax hooks Rails UJS 提供:

#app/assets/javascripts/application.js
$(".button_click").on("ajax:beforeSend", function(){
// preloader load
}).on("ajax:complete", function(){
//preloader hide
});

enter image description here

这将是您所需要的

关于ruby-on-rails - rails link_to with remote => true and jquery on click,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24664684/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com