简体   繁体   English

铁轨3制作一个 <tr> onclick执行与a:remote =&gt; true链接相同的ajax

[英]rails 3 making a <tr> onclick do the same ajax as a :remote => true link

The question title pretty-much says it all. 问题标题非常多地说明了一切。 Basically i'm trying to get each of a table's tr elements to execute the same onclick ajax behaviour as a :remote=>true link would. 基本上我试图让每个表的tr元素执行相同的onclick ajax行为,如:remote => true link will。 It seems it would be a simple thing, but i just can't get my head round which way to approach it! 看起来这将是一件简单的事情,但我只是无法绕过哪条路接近它!

FYI, here's an example of a link that i would want to emulate inside a tr: 仅供参考,这是一个我希望在tr中模拟的链接示例:

link_to "link text here", stream_item, {:remote => true, "data-toggle" => "modal", 'data-target' => "#commentModal"} %>

I guess the approach is either by only using jquery somehow, or something like: 我想这种方法要么只是以某种方式使用jquery,要么类似:

<tr onclick="some stuff here">

Any pointers massively appreciated.. 任何指针都大量赞赏..

Thanks! 谢谢!

I'm guessing that you want to be able to click on the whole table row, not just the text link. 我猜你想要能够点击整个表格行,而不仅仅是文本链接。 In that case, you'll have to employ JS event handlers as you guessed. 在这种情况下,您必须按照猜测使用JS事件处理程序。

  $('#myrow').click(function() {
      $('#mymodal).show();
  });

And then assign the id: 然后分配id:

<tr id="#myrow">Link Text</tr>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM