Php 如何提交许多自动生成表单中的一个表单的值
我有一个包含许多自动生成表单的表(实际上可能有数百个表单)。其代码基于php,如下所示:Php 如何提交许多自动生成表单中的一个表单的值,php,javascript,jquery,Php,Javascript,Jquery,我有一个包含许多自动生成表单的表(实际上可能有数百个表单)。其代码基于php,如下所示: $cellPosition = 0; $rowCounter = 1; $infoCounter = 1; for ($x=0;$x <= count($assetName);$x++) { for ($i=0;$i < count($currentJobs);$i++) { $rowCounter= 1; if ($currentJobs[$i
$cellPosition = 0;
$rowCounter = 1;
$infoCounter = 1;
for ($x=0;$x <= count($assetName);$x++)
{
for ($i=0;$i < count($currentJobs);$i++)
{
$rowCounter= 1;
if ($currentJobs[$i][0] == $table->getCellContents(0,$x))
{
for ($y =0; $y < $currentJobs[$i][10];$y++)
{
$rowCounter++;
}
$table->setCellAttributes ($rowCounter,$cellPosition,"id='jobCell' bgcolor = ". $currentJobs[$i][4]. " rowspan=" . $currentJobs[$i][9]);
$table->setCellContents($rowCounter++,$cellPosition,
"<form id='scheduleForm".$infoCounter++."' method='POST' action='../forms/updateJobForm.php'>".
"<input type='hidden' name='jobInfo' value='" . $currentJobs[$i][1] . "'/>" . " " . "Job# (".$currentJobs[$i][2] . ")<br>" . $currentJobs[$i][3] .
"</form>");
}
else
{
$rowCounter = 1;
}
}
$cellPosition++;
}
echo $table->display();
$cellPosition=0;
$rowCounter=1;
$infoCounter=1;
对于($x=0;$x getCellContents(0,$x))
{
对于($y=0;$y<$currentJobs[$i][10];$y++)
{
$rowCounter++;
}
$table->setCellAttributes($rowCounter,$cellPosition,“id='jobCell'bgcolor=“.$currentJobs[$i][4]”行span=“.$currentJobs[$i][9]);
$table->setCellContents($rowCounter++,$cellPosition,
"".
“..”作业#(“$currentJobs[$i][2]”)
“$currentJobs[$i][3]。
"");
}
其他的
{
$rowCounter=1;
}
}
$cellPosition++;
}
echo$table->display();
我将jobCell(td元素)绑定到以下javascript/jquery代码:
<script>
$(document).ready(function()
{
$("#jobCell").click(function()
{
$(this).children('form').submit();
//$('#scheduleForm').submit();
});
});
</script>
$(文档).ready(函数()
{
$(“#作业单元”)。单击(函数()
{
$(this.children('form').submit();
//$('#scheduleForm')。提交();
});
});
我认为每个jobcell都可以点击,我以前也曾将其放置在点击任何人都可以提交表单的位置。问题是它只会发送表中最后一个jobcell的隐藏信息的信息。现在使用我当前的代码,它只允许用户单击第一个单元格并提交。当我有许多表单时,如何在单击的jobcell中提交隐藏数据?页面上的每个ID应该只有一个。你有很多表格都有相同的ID,很可能只提交最后一个。将id更改为class,同一页面上可以有任何元素具有相同的类 我猜是这样的。但是如果看不到实际的HTML输出,这可能是错误的
<script>
$(document).ready(function()
{
$("#jobCell").click(function()
{
$(this).children('form').submit();
//$('.scheduleForm').submit();
});
});
</script>
$(文档).ready(函数()
{
$(“#作业单元”)。单击(函数()
{
$(this.children('form').submit();
//$('.scheduleForm').submit();
});
});
检查id='jobCell'
是否只设置了一次
我希望代码看起来更像表单id代码:
id='scheduleForm".$infoCounter++."'
如果您可以展示一个演示/示例,只需获取最终生成的html并将其粘贴到JSFIDLE上,就会有所帮助。谢谢你的帮助!我认为他最好使用类名,因为有不止一个id为“jobcell”的元素。。。只是暗示你是对的!一旦我将id切换到类,它就工作得很好。我有同样的想法,但结果相同。您还需要将Jquery选择器更改为类似以下内容:
$(“[id^='jobCell']”)。单击(function()