不返回表单字段值
var formJSON = $.toJSON($('#form1'));
JSP是:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="js/ebs.js"></script>
<script src="js/jquery-ui.js" type="text/javascript"></script>
<script src="js/jquery-1.8.2.js" type="text/javascript"></script>
<script src="js/jquery.min.js" type="text/javascript"></script>
<script src="js/jquery.json-2.4.min.js" type="text/javascript"></script>
<script src="js/jquery.json-2.4.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" onclick="validateField()" method="post">
Text Field 1 : <input id="txt1" name="txt1" type="text" />
<br />
<input type="submit" value="SUBMIT" />
</form>
</body>
</html>
我的JavaScript是:
function validateField() {
alert('fn called');
var formJSON = $.toJSON($('#form1'));
alert('after');
alert('formJSON' + formJSON);
alert("method ends here.");
}
我得到了:
form JSON{"length":1,"0":{"txt1":{},"1":{}},"context":{"location":{}},"selector":"#form1"}
(即使我们在那里输入内容,txt1
字段也没有内容。)