【发布时间】:2013-12-13 09:09:45
【问题描述】:
这是我的代码:
<body>
<h2>Add/Update Person Form</h2>
<div id = "data">
<form id = "person">
<br><br>
Name: <input id = "name" name = "name" type = "text">
<br><br>
Gender: <input name = "gender" type = "radio" value = "Male"> Male
<input name = "gender" type = "radio" value = "Female"> Female
<br><br>
Age: <input id = "age" name = "age" type = "text">
<br><br>
City: <select id = "city" name = "city">
<option>Lahore</option>
<option>Islamabad</option>
<option>Karachi</option>
</select>
<br><br>
<input id = "button" type = "button" value = " Reset " onclick = "ResetForm()">
<input id = "button" type = "button" value = " Add " onclick = "AddData()">
<input id = "button" type = "button" value = " Update ">
</form>
</div>
<h3>List Of Persons</h3>
<div id = "tab">
<table id = "list" cellspacing = "0px" cellpadding = "20px" text-align = "center">
<thead>
<tr>
<td>Name</td>
<td>Gender</td>
<td>Age</td>
<td>City</td>
<td>Action</td>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
这是 JAVASCRIPT 的代码:
<script>
function AddData(){
var x = document.getElementById("age").value;
var y = document.getElementById("name").value;
var letters = '/^[a-zA-Z]+$/';
if((parseInt(x)!=(x))&&(y==parseInt(y))){
alert("Wrong Value Entered");
}
else{
var rows = "";
var name = document.getElementById("gender").value;
var gender = document.getElementById("gender").value;
var age = document.getElementById("age").value;
var city = document.getElementById("city").value;
rows += "<tr><td>" + name + "</td><td>" + gender + "</td><td>" + age + "</td><td>" + city + "</td></tr>";
$(rows).appendTo("#list tbody");
}
}
function ResetForm(){
document.getElementById("person").reset();
}
</script>
现在我想做的是这段代码中有三个按钮。添加、重置、更新。 我现在正在添加重置工作。我已经编写了上面的代码来添加数据,但是当我单击添加时,数据不会添加到表体中。我正在使用 onclick 功能添加数据。所有这些工作都在一个 HTML 页面上完成。我认为问题出在单页上,但我必须在一页上执行此操作。在这方面需要帮助。
【问题讨论】:
-
作为旁注 - 您的 html 中的“ ”需要是“ ” (末尾有分号)
标签: javascript html css html-table add