-1
這是index.php文件無法生成圖形驗證碼數字
<html>
<head>
<script>
function validate() {
var ta = document.getElementById("ta").value;
var answer = document.getElementbyId("answer").value;
var digit1 = parseInt(document.getElementById("digit1").innerHTML);
var digit2 = parseInt(document.getElementById("digit2").innerHTML);
var sum = digit1 + digit2;
if (answer == null || answer == "") {
alert("please add the number");
return false;
}
else if (answer != sum) {
alert("you math is wrong");
}
else if (ta == null || ta == "") {
alert("please fill in the textarea");
}
else {
document.getElementById("status").innerHTML = "processing";
document.getElementById("answer").innerHTML = "";
}
}
function randomNums() {
var rand_num1 = math.floor(Math.random() * 10) + 1;
var rand_num2 = math.floor(Math.random() * 10) + 1;
document.getElementById("digit1").innerHTML = rand_num1;
document.getElementById("digit2").innerHTML = rand_num2;
}
</script>
</head>
<body onload="randomNums();">
<br />
<form action="parse_file.php" method="post" onsubmit="return validate();">
<textarea id="ta" name="ta" rows="8" cols="24" ></textarea>
<br/>
<strong>Add these numbers</strong>
<span id="digit1"></span> +
<span id="digit2"></span> =
<input type="text" id="answer" size="2"; />
<br/>
<input type="submit" value="Submit"/>
</form>
<div id="status"></div>
</body>
</html>
這是parse_file.php
<?php
if(isset($_POST['ta'])) {
ta = $_POST['ta'];
$msg = "hello!";
include("index.php");
}
?>
我不能夠在驗證碼驗證,以生成位數?它只顯示添加這些數字+ =嘗試了很多次編碼中的問題編碼中可能出現的錯誤是什麼?它顯示爲randomNums未在錯誤中定義,並且驗證funit中的某個錯誤是trciky,但無法找到錯誤。爲什麼它沒有在o/p中顯示數字?