我有jQuery脚本正在工作,但我需要从表中提取的值以像俱乐部一样提交。
我需要价值ID以形式提交俱乐部。
<script type="text/javascript">
$("table").on('click','tr',function(e){
e.preventDefault();
var id = $(this).attr('value');
alert(id);
document.forms.league.submit('id')
});
</script>
HTML
<div><form method="post" name="league" action="index.php?cat=$category">
HTML表格
<table>
<thead>
<tr>
<th class="nosort" data-sortcolumn="0" data-sortkey="0-0">Team</th>
<th class="nosort" data-sortcolumn="1" data-sortkey="1-0">Name</th>
<th class="nosort" data-sortcolumn="2" data-sortkey="2-0">Games</th>
<th class="nosort" data-sortcolumn="3" data-sortkey="3-0">Came</th>
<th class="nosort" data-sortcolumn="4" data-sortkey="4-0">Perc</th>
<th data-defaultsort="asc" class="down sorted" data-sortcolumn="5" data-sortkey="5-0">Odds<span class="sign arrow"></span></th>
<th class="nosort" data-sortcolumn="6" data-sortkey="6-0"> </th>
</tr>
</thead>
<tr value="Michael"><td>Michael</td>
<td>Reds</td><td>18</td><td>11</td><td>61.1%</td><td class="sorted">1.64</td><td></td></tr>
</table>
PHP
$sql = "SELECT * FROM results WHERE $position='$club' order by datum desc";
答案 0 :(得分:1)
对代码进行小修改
HTML
<form method="post" id="leagueForm" action="index.php"><input name="cat" type="hidden"/></form>
JS
<script type="text/javascript">
$("table").on('click','tr',function(e){
e.preventDefault();
var id = $(this).attr('value');
alert(id);
var $form = $('#leagueForm');
// set the input value
$form.find('input').val(id);
$form.submit();
});
</script>
PHP
<?php
$submittedID = $_POST['cat'];
// Do whatever you like with the $ submittedID
?>