只有第一个给定的值被插入到表中。变量 i 用于增加 tr 在表中的索引值,它正在增加但值没有插入。其他不添加。想不通为什么。我是 jquery 的新手。
<!DOCTYPE html>
<html>
<head>
<title>My first Page</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
var i=0;
$(document).ready(function(){
$("#hello").click(function(){
var a=$("<td></td>").text($("#test1").val());
var b=$("<td></td>").text($("#test2").val());
var c=$("<td></td>").text($("#test3").val());
var d=$("<td></td>").text($("#test4").val());
var e=$("<td></td>").text($("#test5").val());
$($("table tr").eq(i)).after(e).after(d).after(c).after(b).after(a);
i=i+1;
});
});
</script>
</head>
<body>
<div>
<h1>Hello Talib</h1>
<div>IT</div>
<div>WILL</div>
<div>DISAPPEAR</div>
</div>
First Name: <input type="text" value="fname" id ="test1"><br>
Last Name: <input type="text" value="lname" id="test2"><br>
Roll Number: <input type="text" value="rnum" id="test3"><br>
Faculty:
<select name="Faculty" id="test4">
<option value="CE">Computer Engineering</option>
<option value="BE">Biomedical Engineering</option>
<option value="CV">Civil Engineering</option>
<option value="TE">Telecommunication Engineering</option>
</select>
<br>
Semester:
<input type="radio" value="1st" name="sem" id="test5">1st
<input type="radio" value="2nd" name="sem" id="test5">2nd
<input type="radio" value="3rd" name="sem" id="test5">3rd
<input type="radio" value="4th" name="sem" id="test5">4th
<input type="radio" value="5th" name="sem" id="test5">5th
<input type="radio" value="6th" name="sem" id="test5">6th
<input type="radio" value="7th" name="sem" id="test5">7th
<input type="radio" value="8th" name="sem" id="test5">8th
<br>
<input type="submit" value="Submit"id="hello">
<table border="1" style="border: solid 1px black">
<tr>
<td>First Name</td>
<td>Last Name</td>
<td>Roll Number</td>
<td>Faculty</td>
<td>Semester</td>
</tr>
</table>
</body>
</html>