0
我有以下smarty的代碼來顯示在表....檢索值
<table id="hor-zebra" summary="DIsh Information">
<thead>
<tr>
<th scope="col">Item Name</th>
<th scope="col">Item Price</th>
<th scope="col">Item Type</th>
<th scope="col">Quantity</th>
</tr>
</thead>
{foreach name=f1
item=k
from=$res}
<tbody><tr class="odd">
<td id="bn"> {$k->b_name}</td>
<td> {$k->b_price}</td>
<td> {$k->b_type}</td>
<td> {$k->b_quantity}</td></tr>
<tr><td><a href="javascript:remove()">Remove</a></td>
<td id="resId"></td></tr>
{/foreach}
</tbody></table>
而Ajax代碼是....
function remove(){
var http = GetXmlHttpObject();
http.onreadystatechange = function()
{
if(http.readyState==4)
{
document.getElementById("resId").innerHTML = http.responseText;
//alert(http.responseText);
}
}
var name = document.getElementById("bn").innerHTML;
alert(name);
var url = "index.php?menu=rmv&ajax=ajax&q="+name;
http.open('POST',url,true);
http.send(null);
}
現在問題是,var名稱只返回第一個項目名稱,無論我點擊第二或第三左右.........我需要我想刪除的名稱。但警報只顯示第一.... ...
您的ID「resId」對於所有元素都是相同的。您需要爲循環中的所有元素創建唯一的ID。 – Nitish
我沒有得到....可以ü短暫解釋......請 –
僅供參考,你有你的foreach循環中打開tbody標籤。 –