可以读取JSON的值。同样,我们可以在单击“提交”按钮时将文本框值写入JSON变量
例:`
<html>
<head>
<title>
Sample Employee Details
</title>
<script type="text/javascript" src="emp_json.js">
</script>
</head>
<body>
<form>
<p>Emp ID:<input type="text" id="empid" /></p>
<p>Name:<input type="text" id="name" /></p>
<p>Mobile:<input type="text" id="mob" /></p>
<p><input type="button" value="Add" onclick="add();"/></p>
</form>
<script>
function add()
{
EmployeeDetails.EmployeeID = document.getElementById('empid').value;
EmployeeDetails.Name = document.getElementById('name').value;
EmployeeDetails.Mobile = document.getElementById('mob').value;alert("hi");
}
</script>
</body>
</html>`
我的JSON:
var EmployeeDetails = new Array();
EmployeeDetails = [
{
"EmployeeID":"",
"Name":"",
"Mobile":""
}
];