开发者

Change table row using Rails Ajax

开发者 https://www.devze.com 2023-01-04 02:34 出处:网络
I\'ve a simple page with link_to_remote Rails Ajax function and HTML table. I\'d like to change row of the table when click that link.

I've a simple page with link_to_remote Rails Ajax function and HTML table. I'd like to change row of the table when click that link.

This is my html.

<table border="1">
    <tr>
        <td><div id="ajax_result_1">1</div></td>
        <div id=开发者_StackOverflow社区"ajax_result_2"><td>2</td></div>

    </tr>
    <div id="ajax_result_3">
    <tr>
        <td>3</td>
        <td>4</td>
    </tr>
    </div>
</table>

And this is my code.

<%= link_to_remote 'Change', :update => "ajax_result_1", :url => "change_path" %>

change action just render simple text.

When I use ajax_result_1 for :update, it worked okay.

But, not for ajax_result_2 and ajax_result_3.

Is there a way to solve this? I want to replace row of the table.


<div id="ajax_result_2"><td>2</td></div>

this should be

<td><div id="ajax_result_2">2</div></td>

and

<div id="ajax_result_3">
<tr>
    <td>3</td>
    <td>4</td>
</tr>
</div>

should be

<tr  id="ajax_result_3">
    <td>3</td>
    <td>4</td>
</tr>

you cann't use <div> tag in table directly if you want to use <div> you have to use it in the <td> only.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号