我正在尝试从隐藏的输入传递一些POST变量(使用JQuery根据td字段中的文本更改输入的值)。我已经测试了JQuery,它确实为输入分配了正确的值,但是当我尝试根据上一页的值分配POST变量时,它们没有设置为数字。
代码:
<form method="POST" action="newcriminalreport2.php">
<div style="width:800px;text-align:left;margin:0 auto;padding-bottom:5px;">A. PENDING BALANCE</div>
<table border="1" style="width:800px;" ID="tableA">
<th style="width:40%;"></th>
<th colspan="2" style="width:20%;">CAPITAL</th>
<th colspan="2" style="width:20%;">NON-CAPITAL</th>
<th colspan="2" style="width:20%;">TOTAL</th>
<tr>
<td></td>
<td>Defs</td>
<td>Cases</td>
<td>Defs</td>
<td>Cases</td>
<td>Defs</td>
<td>Cases</td>
</tr>
<tr>
<td>1. Pending Balance from Previous Month</td>
<td id="PendingCapDefs">123</td><input type="hidden" name="PendingCapDefs" id="PendingCapDefsInput">
<td id="PendingCapCases">2</td><input type="hidden" name="PendingCapCases" id="PendingCapCasesInput" value="">
<td id="PendingNonCapDefs">3</td><input type="hidden" name="PendingNonCapDefs" id="PendingNonCapDefsInput" value="">
<td id="PendingNonCapCases">4</td><input type="hidden" name="PendingNonCapCases" id="PendingNonCapCasesInput" value="">
<td id="PendingDefsTotal">5</td><input type="hidden" name="PendingDefsTotal" id="PendingDefsTotalInput" value="">
<td id="PendingCasesTotal">6</td><input type="hidden" name="PendingCasesTotal" id="PendingCasesTotalInput" value="">
</tr>
</table>
<br/><br/><div style="width:800px;text-align:left;margin:0 auto;padding-bottom:5px;">B. CRIMINAL CASE ASSIGNMENTS</div>
<table border="1" style="width:800px;" ID="tableB">
<th style="width:40%;"></th>
<th colspan="2" style="width:20%;">CAPITAL</th>
<th colspan="2" style="width:20%;">NON-CAPITAL</th>
<th colspan="2" style="width:20%;">TOTAL</th>
<tr>
<td></td>
<td>Defs</td>
<td>Cases</td>
<td>Defs</td>
<td>Cases</td>
<td>Defs</td>
<td>Cases</td>
</tr>
<tr>
<td>2. New Fillings</td>
<td><input type="text" name="username" size="5" id="AsgNewCapDefs"/></td>
<td><input type="text" name="username" size="5" id="AsgNewCapCases"/></td>
<td><input type="text" name="username" size="5" id="AsgNewNonCapDefs"/></td>
<td><input type="text" name="username" size="5" id="AsgNewNonCapCases"/></td>
<td id="AsgNewTotalDefs">234</td>
<td id="AsgNewTotalCases">345</td>
</tr>
<tr>
<td>3. Transfers Received</td>
<td><input type="text" name="username" size="5" id="AsgTRCapDefs"/></td>
<td><input type="text" name="username" size="5" id="AsgTRCapCases"/></td>
<td><input type="text" name="username" size="5" id="AsgTRNonCapDefs"/></td>
<td><input type="text" name="username" size="5" id="AsgTRNonCapCases"/></td>
<td id="AsgTRTotalDefs">234</td>
<td id="AsgTRTotalCases">345</td>
</tr>
<tr>
<td>4. Reopened Cases</td>
<td><input type="text" name="username" size="5" id="AsgRCCapDefs"/></td>
<td><input type="text" name="username" size="5" id="AsgRCCapCases"/></td>
<td><input type="text" name="username" size="5" id="AsgRCNonCapDefs"/></td>
<td><input type="text" name="username" size="5" id="AsgRCNonCapCases"/></td>
<td id="AsgRCTotalDefs">234</td>
<td id="AsgRCTotalCases">345</td>
</tr>
<tr>
<td>5. Total Cases Assigned</td>
<td id="PendingCapDefsTotal"/>0</td><input type="hidden" name="PendingCapDefsTotal" id="PendingCapDefsTotalInput" value="">
<td id="PendingCapCasesTotal"/>0</td><input type="hidden" name="PendingCapCasesTotal" id="PendingCapCasesTotalInput" value="">
<td id="PendingNonCapDefsTotal"/>0</td><input type="hidden" name="PendingNonCapDefsTotal" id="PendingNonCapDefsTotalInput" value="">
<td id="PendingNonCapCasesTotal"/>0</td><input type="hidden" name="PendingNonCapCasesTotal" id="PendingNonCapCasesTotalInput" value="">
<td id="PendingTotalDefs">0</td><input type="hidden" name="PendingTotalDefs" id="PendingTotalDefsInput" value="">
<td id="PendingTotalCases">0</td><input type="hidden" name="PendingTotalCases" id="PendingTotalCasesInput" value="">
</tr>
</table>
<br />
<div style="text-align:right; width: 900px;"><input type="submit" value="Save and Continue -->" style="border:none;background-color:transparent;color:blue;text-decoration:underline"></form>
和下一页:
<?php
session_start();
$judge = $_SESSION['judge'];
if(!isset($_SESSION['user'])){
header( 'Location: index.php' );
die();
}
// Get line 1 and 5 from first page (to be used in newcriminalreport3 totals)
$_SESSION['PendingCapDefs'] = $_POST['PendingCapDefs'];
$_SESSION['PendingCapCases'] = $_POST['PendingCapCases'];
$_SESSION['PendingNonCapDefs'] = $_POST['PendingNonCapDefs'];
$_SESSION['PendingNonCapCases'] = $_POST['PendingNonCapCases'];
$_SESSION['PendingDefsTotal'] = $_POST['PendingDefsTotal'];
$_SESSION['PendingCasesTotal'] = $_POST['PendingCasesTotal'];
$_SESSION['PendingCapDefsTotal'] = $_POST['PendingCapDefsTotal'];
$_SESSION['PendingCapCasesTotal'] = $_POST['PendingCapCasesTotal'];
$_SESSION['PendingNonCapDefsTotal'] = $_POST['PendingNonCapDefsTotal'];
$_SESSION['PendingNonCapCasesTotal'] = $_POST['PendingNonCapCasesTotal'];
$_SESSION['PendingTotalDefs'] = $_POST['PendingTotalDefs'];
$_SESSION['PendingTotalCases'] = $_POST['PendingTotalCases'];
?>
任何人都知道发生了什么事?
的print_r($ _ POST):
Array ( [PendingCapDefs] => [PendingCapCases] => [PendingNonCapDefs] => [PendingNonCapCases] => [PendingDefsTotal] => [PendingCasesTotal] => [username] => 0 [PendingCapDefsTotal] => [PendingCapCasesTotal] => [PendingNonCapDefsTotal] => [PendingNonCapCasesTotal] => [PendingTotalDefs] => [PendingTotalCases] => )
<script type="text/javascript">
$(window).unload( function () {
// Line 1
$('#PendingCapDefsInput').val($('#PendingCapDefs').html());
$('#PendingCapCasesInput').val($('#PendingCapCases').html());
$('#PendingNonCapDefsInput').val($('#PendingNonCapDefs').html());
$('#PendingNonCapCasesInput').val($('#PendingNonCapCases').html());
$('#PendingDefsTotalInput').val($('#PendingDefsTotal').html());
$('#PendingCasesTotalInput').val($('#PendingCasesTotal').html());
// Line 5
$('#PendingCapDefsTotalInput').val($('#PendingCapDefsTotal').html());
$('#PendingCapCasesTotalInput').val($('#PendingCapCasesTotal').html());
$('#PendingNonCapCasesTotalInput').val($('#PendingNonCapCasesTotal').html());
$('#PendingTotalDefsInput').val($('#PendingTotalDefs').html());
$('#PendingTotalCasesInput').val($('#PendingTotalCases').html());
});
</script>
答案 0 :(得分:1)
$('#PendingCapDefsInput').val($('#PendingCapDefs').html());
输入元素没有html,因此在将表单数据发送到服务器之前,您将在页面卸载时擦除表单内容。由于您只是直接向服务器提交,为什么还要打扰jquery“按摩”呢?