[英]How to call a “link_to” in Javascript on a onclick event
I'm trying to get the rails-'link_to' funcionality in my Javascript (jQuery). 我正在尝试在我的Javascript(jQuery)中获得rails-'link_to'功能。 In my Javascript I'm waiting for a onclick event and fetch some data via ajax.
在我的Javascript中,我正在等待onclick事件并通过ajax获取一些数据。 Afterwards I would like to call a
之后,我想打电话给
= link_to "Show", @mymodel, :remote => true, :id => "#{some.id}", :format => :js
But I cant figure out how to put it in JS. 但我不知道如何将其放入JS。 Thanks a ton for your help!
多谢您的协助!
If you are using jquery you can attach a click event on the anchor tag after it has been created with your RoR code, like so 如果您使用的是jquery,则可以在使用RoR代码创建了锚事件后将click事件附加到锚事件标签上,如下所示
$(document).ready(function(){
$('#theid').click(function(){
//do something here
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.