jQuery根据表数据的类改变表数据的内容

时间:2014-02-06 10:49:46

标签: javascript jquery html

我有下表,其中填充了在运行时从数据库中获取的数据:

                while($stmt -> fetch()){
                //While there is still data being fetched, make the table rows below
                    echo "<tr data-id='$matchid'><td>
<img class='delete_imgs' data-id='$matchid' src='Images/delete_icon.png'>
<img class='edit_imgs' data-id='$matchid'src='Images/edit_icon.png'></td>
                            <td id='hero_column$matchid'>$hero</td>
                            <td id='result_column$matchid'>$result</td>
                            <td id='gamemode_column$matchid'>$gamemode</td>
                            <td id='mmr_column$matchid'>$mmr</td>
                            <td id='confirm_button$matchid all_cons' style='display: none'><img src='Images/confirm.png'></td>
                            </tr>";         
                }

重要的部分是<td>行。我希望使用jQuery来编辑该单元格的内容。例如,我有<td id='hero_column11>randomdata</td>(11是其潜在的运行时值)。如何使用jQuery将“randomdata”更改为其他内容?

2 个答案:

答案 0 :(得分:1)

试试这个:

$(document).ready(function(){
    $(document).find('td[id^="hero_column"]').html('new value');
});

我已将其添加到document.ready()内,但您可以在点击按钮或其他内容时将其插入

答案 1 :(得分:0)

尝试:     $('#hero_column11')。html('新数据');

您可以在按钮或链接的onclick事件中加入此内容。

相关问题