use the onbluer
event in the input of the form form, and the parameters in the calling function are invalid if the native php code is invalid.
<?php
$total = 0;
foreach($data as $product):
?>
<tr id="tr-<?php echo $product["id"] ?>" class="products">
<td bgcolor="-sharpffffff" align="center" style="width:300px;">
<a href="" target="_blank"><img style="width:80px; height:80px;" src="<?php echo $product["cover"] ?>" border="0" title="<?php echo $product["title"] ?>"></a><br>
<a href="" target="_blank" class="f6"><?php echo $product["title"] ?></a>
</td>
<td align="center" bgcolor="-sharpffffff"><?php echo $product["originalprice"] ?></td>
<td align="center" bgcolor="-sharpffffff"><span id="p-<?php echo $product["id"] ?>"><?php echo $product["price"] ?></span></td>
<td align="center" bgcolor="-sharpffffff">
<input type="text" name="goods_number" value="<?php echo $product["num"] ?>" size="4" class="inputBg" style="text-align:center " onblur="changeNum(<?php echo $product["id"] ?>, this.value)" id="product-<?php echo $product["id"] ?>" >
</td>
<td align="center" bgcolor="-sharpffffff"><span id="total-<?php echo $product["id"] ?>"><?php echo $product["num"]*$product["price"] ?></span></td>
<td align="center" bgcolor="-sharpffffff">
<a href="javascript:delPro(<?php echo $product["id"] ?>);" class="f6"></a>
</td>
</tr>
<?php
$total += $product["price"]*$product["num"];
endforeach;
?>
<script type="text/javascript">
function changeNum(productid, num){
alert(productid);
alert(num);
//ajax
var url = "changeNum.php";
var data = {"productid":productid, "num":num};
var success = function(response){
if(response.errno == 0){
var price = ($("-sharpproduct-"+productid).val())*($("-sharpp-"+productid).html());
$("-sharptotal-"+productid).html(price);
}
}
$.post(url, data, success, "json");
}
</script>
use alert
pop-up to check whether onbluer
is valid, and find onblur= "changeNum ( php echo $product ["id"]? >, this.value)"
in consloe
there is no way to pass the value. In fact, the data has already been fetched from the database. ( this.value
is the value of num
extracted from the database) change the first way to pass the parameter using native php. Thank you very much!