简体   繁体   中英

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. 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:

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:

<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.

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

And then assign the id:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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