您需要ajax将发票从服务器发回客户端。请了解更多关于ajax和jquery的一些谷歌搜索...教程你将获得成千上万的。
crossorigin="anonymous">
Calculate Profit
$('document').ready(function(){
$('button').on('click',function(event){
event.preventDefault();
var units= $("#product_unit").val();
var wholesale_price=$("#wholesale_price").val();
var sell_price=$("#sell_price").val();
var profit = (units*sell_price)-(units*wholesale_price);
$('#profit').val(profit);
var data = $('form').serialize();
$.ajax({
type : "POST",
data : data,
url : "invoice.php",
dataType : "html",
success : function(response){
$('#invoice').html(response);
},
error : function(obj){
console.log(obj);
}
});
});
});
invoice.php 强>
$unit = $_POST["units"];
$wholesale = $_POST["wholesale_price"];
$sell = $_POST["sell_price"];
function invoice_profit($units, $wholesale, $sell)
{
return ($units * $sell) - ($units * $wholesale);
}
echo "Invoice #0001";
echo "
echo "
";echo "
" . $_POST["date"] . "";echo "
" . $_POST["product_name"] . "";echo "
" . $_POST["units"] . "";echo "
" . $_POST["wholesale_price"] . "";echo "
" . $_POST["sell_price"] . "";echo "
" . invoice_profit($unit, $wholesale, $sell) . "";echo "
";echo "
";?>
结果:
然后你必须根据你的设计设置表格