有人可以看看这些吗,它只是不适合我,它是一个 html 表单、一个用于处理它的 php 文件和一个 javascript 文件,来自浏览器中的错误显示 JScript 文件中的 U+12AF 幻像非法字符之类的东西,已经进行了 1.5 个小时,我束手无策。
--submit.js--
$(document).ready(function() {
$(function() {
$('#paycheck').bind('submit', function() {
$.post('Paycheck.php', $("#paycheck").serialize(), function(data) {
$('#result').html(data);
});
});
});
});
--Paycheck.html--
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<pre><title>Weekly Gross Paycheck Calculator</title></pre>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="submit.js"></script>
</head>
<body>
<h2 style = "text-align:center">PayCheck</h2>
<form name="paycheck" id="paycheck" action="" method="POST">
<p>Number of Hours: <input type="text" name="numHours"/></p>
<p>Hourly Wage $<input type="text" name="hourlyWage"/></p>
<p><input type="reset" value="Clear Form" />
<input type="submit" name="submit" value="Send Form" /></p>
</form>
<!-- Form and javascript will output the results here -->
<div id="result"></div>
</body>
</html>
--Paycheck.php--
<?php
function validateInput($data, $fieldName){
global $errorCount;
if (empty($data)) {
echo "\"$fieldName\" is a required field.<br/>\n";
++$errorCount;
$retval = "";
} else { // Only clean up the input if it isn't empty
if (!is_numeric($data)){
echo "\"$fieldName\" must be numeric.<br/>\n";
++$errorCount;
$retval = "";
}else{
$retval = trim($data);
$retval = stripslashes($retval);
}
return($retval);
} // end validateInput()
}
$ShowForm = TRUE;
$errorCount = 0;
$numHours = "";
$hourlyWage = "";
$wage = "";
if (isset($_POST['Submit'])) {
$numHours = validateInput($_POST['numHours'],"Number of Hours");
$hourlyWage = validateInput($_POST['hourlyWage'],"Hourly Wage");
if ($errorCount==0)
$ShowForm = FALSE;
else
$ShowForm = TRUE;
}
echo $numHours ." " . $hourlyWage;
if ($ShowForm == TRUE) {
if ($errorCount > 0)// if there were errors
print "<p>Please re-enter the form information below.</p>\n";
} else {
//If hours are over 40 then use time and a half
if($numHours > 40) { $wage = ((($numHours - 40) * 1.5) * $hourlyWage) + ($hourlyWage * 40); }
//otherwise use normal multiplication.
else { $wage = $numHours * $hourlyWage; }
print "<p>Your weekly gross salary is $". $wage . ".</p>\n";
}
?>