读取 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":""
}
];