gpt4 book ai didi

javascript - 如何设置 jquery onclick 函数以仅针对可编辑表中的特定表列或类?

转载 作者:行者123 更新时间:2023-11-29 12:08:36 24 4
gpt4 key购买 nike

我想让我的表格仅可编辑具有 Home_Score 和 Away_Score 名称的列

//编辑.js文件

$(function() {

//when a td element within tbody is clicked
$('tbody').on('click','td',function() {
//call displayform, passing td jQuery element
displayForm( $(this) );
});

});

//table.php文件

<?php 

$sql = "SELECT * FROM predict WHERE Fixture_ID BETWEEN '1' and '10' ";
$results = $dbh->query($sql);
$rows = $results->fetchAll();

foreach ($rows as $row) {
echo '<tr id="'.$row['Fixture_ID'].'">';
echo '<td class="Home_Team">'.$row['Home_Team'].'</td><td class="Home_Score">'.$row['Home_Score'].'</td>';
echo '<td class="Away_Score">'.$row['Away_Score'].'</td><td class="Away_Team">'.$row['Away_Team'].'</td>';
echo '</tr>';
}
?>

最佳答案

假设您要添加行,您可以将一个类添加到您放置值的行

<?php 

$sql = "SELECT * FROM predict WHERE Fixture_ID BETWEEN '1' and '10' ";
$results = $dbh->query($sql);
$rows = $results->fetchAll();

foreach ($rows as $row) {
echo '<tr id="'.$row['Fixture_ID'].'">';
echo '<td class="Home_Team">'.$row['Home_Team'].'</td><td class="Home_Score editable">'.$row['Home_Score'].'</td>';
echo '<td class="Away_Score editable">'.$row['Away_Score'].'</td><td class="Away_Team">'.$row['Away_Team'].'</td>';
echo '</tr>';
}
?>

然后您可以更新您的选择器

$('tbody').on('click','.editable',function() {

关于javascript - 如何设置 jquery onclick 函数以仅针对可编辑表中的特定表列或类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31077800/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com