从 smarty 中检索值并在 ajax 中显示
我有以下 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 name 只返回第一个项目名称,无论我单击第二个还是第三个等等...... ......我需要我想删除的名称。但警报仅显示第一个......
I have the following smarty code to display in table....
<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>
And the ajax code is....
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);
}
Now the problem is that var name is returning only the first Item Name whether i click 2nd or 3rd or so on.........I need the name which i want to remove.But alert showing only the 1st.......
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
并将你的 javascript 更改为:
让我知道它是否有效。
Try this :
And change you javascript to :
Let me know if it worked or not .