完整的代码如下:
HTML code:
<>
<div>
<form name="form_order" method="post" action="?action=$atc" enctype="multipart/form-data">
<div>
<div>
<>
<ul>
<li><div><input type="checkbox" name="" id="" checked="checked" /> 全选</div></li>
<li>商品</li>
<li>返积分</li>
<li>数量</li>
<li>单价</li>
<li>总价</li>
</ul>
<>
<ul id="tr$rs[id]">
<li><input type="checkbox" name="" id="" checked="checked" /></li>
<li><a href="bencandy.php?city_id=$rs[city_id]&fid=$rs[fid]&id=$rs[id]" target="_blank"><img src="$rs[picurl]"height="90" onError="this.src='$webdb[www_url]/images/default/nopic.jpg'"/></a><h3><a href="bencandy.php?city_id=$rs[city_id]&fid=$rs[fid]&id=$rs[id]" target="_blank">$rs[title]</a></h3><p>$rs[content]</p></li>
<li>0分</li>
<li>{$rs[num]}</li>
<li><font>{$rs[price]}</font>元</li> <li><font id="showid$rs[id]">{$rs[price2]}</font>元</li> </ul>
<>
<ul>
<div>
<p>
运送方式:
<>
<select id="collect" name="postdb[youfei]" onchange="Add(this.value,'total$rs[uid]')">
<option value='10'>快递:10元</option>
<option value='20'>EMS:20元</option>
<option value='50'>平邮:50元</option>
</select>
<SCRIPT LANGUAGE="JavaScript">
<; }
else if(type==0){ //删除
num=0 }
if(type!=0 && num==0){
alert('数量不能小于1,若不想购买,请选择删除');
num=1; }
$("#numid"+id).val(num);
$("#showid"+id).html(changeTwoDecimal(String(num*price))); obj=$(".shows"+uid);
thispice = 0;
for(i=0;i<obj.size();i++){
thispice+=parseFloat(obj.eq(i).html()); }
$("#total"+uid).html(thispice); if(type==0){
$.get("join.php?type=setcookie&cid="+id+"&num="+0); $("#tr"+id).hide(); }else{
$.get("join.php?type=setcookie&cid="+id+"&num="+num+"&"+Math.random()); } obj2 = $(".totalprice");
if(obj2.size()>1){ thispice = 0; for(i=0;i<obj2.size();i++){
thispice+=parseFloat(obj2.eq(i).html()); }
$("#total_all").html(thispice); } }
function changeTwoDecimal(x){
var f_x = parseFloat(x);
if(isNaN(f_x)){
alert('function:changeTwoDecimal->parameter error');
return false; }
var f_x = Math.round(x*100)/100; return f_x; }
function Add(m,id){ document.getElementById(id).innerHTML = parseInt(document.getElementById(id).getAttribute("total")+parseInt(m)) //--> </SCRIPT>
<>
</p>
<p><strong>店铺商品合计:
</strong>(含运费) <font id="total$rs[uid]">$total</font>元</p>
</div>
<div>
<p><stron>卖家:{$rs[username]}</strong></p>
<p>给卖家留言:<textarea name='postdb[content]' id='atc_content' >$rsdb[content]</textarea></p>
</div>
</ul>
<>
<>
<ul><div><strong>商品总价:</strong>(含运费) <font id="total_all">$total_all</font>元</div></ul> <>
</div>
</div>
<div></div> <div>
<div>
<div>
<p><span>实付款:</span>
<>
<font id="total$rs[uid]">$total_ll</font>元
<>
<font id="total$rs[uid]">$total</font>元
<> </p> {$address_selects}
</div>
</div>
<div>
<input type="submit" name="imageField" id="imageField" value=" " /> <input type="hidden" name="fid" value="$fid"> <input type="hidden" name="id" value="$id"> <input type="hidden" name="cid" value="$cid"> <input type="hidden" name="postdb[title]" id="atc_title" size="50" value="$infodb[title]"> </div>
<>
<SCRIPT LANGUAGE="JavaScript">
<>
</SCRIPT>
<a href="?action=del&id=$id&cid=$cid&fid=$rsdb[fid]">删除</a>
<>
</div>
<script language="JavaScript">
<>
</script>
</form>
</div>
<>
<div>
</div>
</div>
<>
想要的效果是:
当我选择ems20运费时,在运送方式中点击下拉框中的运费时那么就用 店铺合计总价+ 20元 当我点击平邮50元时,店铺合计总价+ 50元.
我说的要二个地方显示,是因为他如果存在二个不同的商家的商品时,会有二个商家合起来的总价和 商家商品本身的总价。
解决方法如下:
<select id="collect" name="postdb[youfei]" onchange="Add(this.value,'total$rs[uid]')">
<option value='10'>快递:10元</option>
<option value='20'>EMS:20元</option>
<option value='50'>平邮:50元</option>
</select>
对name=”postdb[youfei]“属性进行操作,在action中设置名为postdb[youfei]的参数,即:private String postdb[youfei],然后生成get/set方法,就可以取到值了!