Javascript 函数删除和更新总计不';行不通
我有一个购物车,删除和更新总不工作。 在“我的删除”按钮中,它删除删除,但不删除整个表格。在我的更新中,每当我删除一些产品时,总数都不会更新 JS代码Javascript 函数删除和更新总计不';行不通,javascript,jquery,Javascript,Jquery,我有一个购物车,删除和更新总不工作。 在“我的删除”按钮中,它删除删除,但不删除整个表格。在我的更新中,每当我删除一些产品时,总数都不会更新 JS代码 function remove(id) { var i=findpos(id); totalprice-=purchased[i].price*purchased[i].cnt; purchased[i].cnt = 0; $('#table_'+id).remove(); update_total()
function remove(id)
{
var i=findpos(id);
totalprice-=purchased[i].price*purchased[i].cnt;
purchased[i].cnt = 0;
$('#table_'+id).remove();
update_total();
}
function update_total()
{
if(totalprice)
{
$('#total').html('total: $'+totalprice);
$('a.button').css('display','block');
}
else
{
$('#total').html('');
$('a.button').hide();
}
}
我的桌子
<table width="260" id="table_'.$row['id'].'">\
<tr>\
<input type="text" name="id[]" value="'.$row['id'].'"></td>
<td width="60%"><input type="text" readonly="readonly" name="roomname[]" value="'.$row['name'].'" ></td>
<td width="10%"><input type="text" name="price[]" readonly="readonly" value="'.$row['price'].'" ></td>
<td width="15%"><select name="qty[]" id="'.$row['id'].'_cnt" onchange="change('.$row['id'].');" >
<option value="1">1</option>\
<option value="2">2</option>
<option value="3">3</option>
</select>
<td width="15%"><a href="#" onclick="remove('.$row['id'].');return false;" class="remove">remove</a></td>\
\
\
1\
2.
3.
\
任何试图使用此代码的人的提示。如果您使用的是Chrome 24或更高版本和FF 27,则需要在script.js中重命名remove()函数,因为这些新浏览器具有名为remove的内置DOM功能。如果不重命名该功能,您将无法从购物车中删除项目。我刚刚重命名了函数本身以及在“addtocart.php”中对它的调用
这些必须是变化。
功能rmv(id)
{
var i=findpos(id)
调用addtocart.php
table width="260" id="table_'.$row['id'].'">\
<tr>\
<input type="text" name="id[]" value="'.$row['id'].'"></td>
<td width="60%"><input type="text" readonly="readonly" name="roomname[]" value="'.$row['name'].'" ></td>
<td width="10%"><input type="text" name="price[]" readonly="readonly" value="'.$row['price'].'" ></td>
<td width="15%"><select name="qty[]" id="'.$row['id'].'_cnt" onchange="change('.$row['id'].');" >
<option value="1">1</option>\
<option value="2">2</option>
<option value="3">3</option>
</select>
<td width="15%"><a href="#" onclick="rmv('.$row['id'].');return false;" class="remove">remove</a></td>\
table width=“260”id=“table”.$row['id']”>\
\
1\
2.
3.
\
我建议您更新会话中的值只要初始化总数,如果它还没有设置,它不会更新,因为它总是在您的代码上方声明,然后将提交的值添加到提交的当前会话变量(session\u variable+=post\u value
)Whoa我不知道如何开始。您能帮忙吗?
table width="260" id="table_'.$row['id'].'">\
<tr>\
<input type="text" name="id[]" value="'.$row['id'].'"></td>
<td width="60%"><input type="text" readonly="readonly" name="roomname[]" value="'.$row['name'].'" ></td>
<td width="10%"><input type="text" name="price[]" readonly="readonly" value="'.$row['price'].'" ></td>
<td width="15%"><select name="qty[]" id="'.$row['id'].'_cnt" onchange="change('.$row['id'].');" >
<option value="1">1</option>\
<option value="2">2</option>
<option value="3">3</option>
</select>
<td width="15%"><a href="#" onclick="rmv('.$row['id'].');return false;" class="remove">remove</a></td>\