简体   繁体   English

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

[英]jQuery changing contents of table data based on table data's class

I have the following table that is populated with data taken from a database at runtime: 我有下表,其中填充了在运行时从数据库获取的数据:

                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>";         
                }

The important parts are the <td> lines. 重要的部分是<td>行。 I wish to use jQuery to edit the contents of that cell. 我希望使用jQuery编辑该单元格的内容。 So for example, I have <td id='hero_column11>randomdata</td> (the 11 being its potential runtime value). 因此,例如,我有<td id='hero_column11>randomdata</td> (11是其潜在的运行时值)。 How do I use jQuery to change the 'randomdata' into something else? 如何使用jQuery将“ randomdata”更改为其他内容?

try this: 尝试这个:

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

I have include it inside document.ready() but you can insert it when you click a button or soething else 我已经将其包含在document.ready()但是您可以在单击按钮或进行其他调整时将其插入

Try with: $('#hero_column11').html('new data'); 试试:$('#hero_column11')。html('new data');

You can include this in a onclick event on a button or a link. 您可以将其包含在按钮或链接的onclick事件中。

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

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