[英]Submit button in php mysql table
我有的:
<table class="sortable table table-hover table-bordered">
<thead>
<tr>
<th>CPU</th>
<th>Speed</th>
<th>Cores</th>
<th>TDP</th>
<th>Preformace</th>
<th>Overclocing</th>
<th>Price</th>
<th>Buy</th>
</tr>
</thead>
<tbody>
<?php $i=0 ;
do {
$preformace = $row_Procesory['Preformace'];
$over = $row_Procesory['Overclocing'];
$i++; ?>
<tr>
<td><?php echo $row_Procesory['CPU']; ?></td>
<td><?php echo $row_Procesory['Speed']; ?></td>
<td><?php echo $row_Procesory['Cores']; ?></td>
<td><?php echo $row_Procesory['TDP']; ?></td>
<td><?php echo "
<script type='text/javascript'>
$(document).ready(function() {
$('#progressbarP$i').height(10).progressbar({
value : 1
});
$('#progressbarP$i .ui-progressbar-value').animate(
{width: '$preformace%'},{queue: false});
});
</script>
<div id='progressbarP$i' title='$preformace'></div>
";?></td>
<td><?php echo "
<script type='text/javascript'>
$(document).ready(function() {
$('#progressbarO$i').height(10).progressbar({
value : 1
});
$('#progressbarO$i .ui-progressbar-value').animate({
width: '$over%'
}, 1000);
});
</script>
<div id='progressbarO$i' title='$over'></div>
";?></td>
<td><?php echo $row_Procesory['Price']; ?></td>
<!-- BUTTON SECTION -->
<td><?php echo "<button class='btn btn-success' type='button' align='CENTER'>Add</button>";?></td>
</tr>
<?php } while ($row_Procesory = mysql_fetch_assoc($Procesory)); ?>
</tbody>
</table>
基本上,即时通讯遍历mysql并显示行。 在preformace和超频列中,im显示带有mysql值的动画jquery progresbar。 我还使用bootstrap和sortable.js使表可排序。
我想要的是:单击添加按钮时,处理器的名称将作为变量发送到test.php。 我什至不知道如何用jquery定位name元素:D
如果我明白您的问题,那么这里可以提供帮助
<table class="sortable table table-hover table-bordered">
<thead>
<tr>
<th>CPU</th>
<th>Speed</th>
<th>Cores</th>
<th>TDP</th>
<th>Preformace</th>
<th>Overclocing</th>
<th>Price</th>
<th>Buy</th>
</tr>
</thead>
<tbody>
<?php $i=0 ;
do {
$preformace = $row_Procesory['Preformace'];
$over = $row_Procesory['Overclocing'];
$i++; ?>
<tr>
<td><?php echo $row_Procesory['CPU']; ?></td>
<td><?php echo $row_Procesory['Speed']; ?></td>
<td><?php echo $row_Procesory['Cores']; ?></td>
<td><?php echo $row_Procesory['TDP']; ?></td>
<td><?php echo "
<script type='text/javascript'>
$(document).ready(function() {
$('#progressbarP$i').height(10).progressbar({
value : 1
});
$('#progressbarP$i .ui-progressbar-value').animate(
{width: '$preformace%'},{queue: false});
});
</script>
<div id='progressbarP$i' title='$preformace'></div>
";?></td>
<td><?php echo "
<script type='text/javascript'>
$(document).ready(function() {
$('#progressbarO$i').height(10).progressbar({
value : 1
});
$('#progressbarO$i .ui-progressbar-value').animate({
width: '$over%'
}, 1000);
});
</script>
<div id='progressbarO$i' title='$over'></div>
";?></td>
<td><?php echo $row_Procesory['Price']; ?></td>
<!-- BUTTON SECTION -->
<td><?php echo "<button class='btn btn-success pro_btn' processor = '".$row_Procesory['CPU']."' type='button' align='CENTER'>Add</button>";?></td>
</tr>
<?php } while ($row_Procesory = mysql_fetch_assoc($Procesory)); ?>
</tbody>
</table>
该解决方案( 处理器属性 )是避免选择器,如果需要,我们可以提供其他选择器
$('.pro_btn').die('click').live('click',function(e){
var name = $(this).attr('processor');
$.post('test.php',{'processor_name':name}, function(response) {
// log the response to the console
console.log("Response: "+response);
});
});
如果您不想使用该属性,则可以执行以下操作
var name = $(this).closest('tr').find('td:first').text();
我希望这可以帮助:)
捕获点击事件并找到最接近的“ tr”,然后找到该“ tr”的第一个“ td”。 就像这样:
$(this).closest('tr').find('td:first').text();
或获取按钮的括号,即td和它们的td的父对象。 那就是tr。 最后得到第一个TD。
$(this).parent().parent().find('td:first').text();
或者只是将其他属性添加到您的按钮,然后获取值。
$(this).attr('processor');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.