我有以下代码,哪种工作,除了我得到相同的答案在所有行上重复。jQuery .each()重复所有行的答案
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>each demo</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<span>(click here to change)</span>
<table width="50%" border="0" cellspacing="2" cellpadding="2">
<tr>
<th scope="col">Part Number</th>
<th scope="col">Result</th>
</tr>
<tr>
<td id="pn">84ps01</td>
<td class="div1"> </td>
</tr>
<tr>
<td id="pn">92K002</td>
<td class="div1"> </td>
</tr>
<tr>
<td id="pn">68F017</td>
<td class="div1"> </td>
</tr>
</table>
<script>
$("span").click(function() {
var pn = $("#pn").text();
$("td#pn").each(function() {
$(".div1").load("data.asp?prodref="+($(this).text()))
});
});
</script>
$(this).("#div1").load("data.asp?prodref="+pn+"#result");
</body>
</html>
data.asp
是一个简单的页面,查询使用request.querystring("prodref")
返回结果的数据库。
所以我想获取表的每一行来查询数据库并返回结果。
这里'$(”。DIV1 “)。负载(” data.asp?prodref = “+($(this).text()))''''在'.each()'函数的每次迭代中,您将数据加载到每个具有'div1'类的元素中。这不是jQuery的错,jQuery完全按照你的要求去做。 –