<script type="text/javascript">
var pathName = document.location.pathname;
var index = pathName.substr(1).indexOf("/");
var app = pathName.substr(0, index + 1);
var xmlhttp;
function load(url, func) {
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = func;
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
function check(number) {
load(app + "/checknumber?guessnumber=" + number, function () {
if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
checkingdiv = document.getElementById("checking");
checkingcontent = xmlhttp.responseText;
if (checkingcontent.trim().length === 0) {
checkingdiv.removeAttribute("style");
} else {
checkingdiv.setAttribute("style", "border: 1px dashed blue;");
}
checkingdiv.innerHTML = checkingcontent;
}
});
}
</script>
调用部分:
<table>
<tr>
<td> <input type="text" name="number" /></td>
<td><input type="submit" value="猜" onclick="check(<%=request.getParameter("number")%>)"/></td>
<td><div id="checking"></div></td>
</tr>
</table>
风筝_0010