在点击行上提交 [英] On click row to submit

查看:97
本文介绍了在点击行上提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有正在使用的jQuery脚本,但我需要表中的值才能以Club之类的形式提交.

I have jQuery script who is working, but i need that value from table to submit in form like club.

我需要价值ID才能像俱乐部一样以表格形式提交.

I need value ID to submit like club in form.

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

推荐答案

对代码的小修改

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

?>

这篇关于在点击行上提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆