javascript - 如何将价格与金额相乘?

标签 javascript php

如何将价格与金额相乘并显示结果。这是我想要将所选价格与所选金额相乘并显示结果的代码:

?>
<!DOCTYPE html>
<head>
<title>Order</title>
<link href="css/style.css" media="screen" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="css/custom.css" />
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<link rel="stylesheet" href="buttons.css">
</head>

<body>

$_SESSION['link'] = $_POST['link'];
echo '<img src="'.$_SESSION['link'] .'">'; 
?>

Order

<form action="" method="post" id="register-form" novalidate="novalidate">
ProductID: <input type="text" name="ProductID" id="ProductID">
Color: <input type="text" name="Color" id="Color">
Amount: <input type="number" name="Amount" id="Amount">
Price: echo ''.$_SESSION['price'].'';
?>

<input type="submit" name="submit" value="Submit" class="button">

</form> 

<script>

最佳答案

Demo on JS Fiddle.

HTML + PHP:

<form action="" method="post" id="register-form" novalidate="novalidate">
    ProductID: <input type="text" name="ProductID" id="ProductID"/>
    Color: <input type="text" name="Color" id="Color"/>
    Amount: <input type="number" name="Amount" id="Amount"/>
    Price: <span id="price"><?php echo $_SESSION['price']; ?></span>
    <br/>
    Result: <span id="result"></span>

JS:

$('#Amount').keyup(function() {
   var price = parseFloat($('#price').text());
   $('#result').text(price * parseFloat($(this).val()));
});

关于javascript - 如何将价格与金额相乘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30976887/

相关文章:

javascript - jQuery.change() 与 addEventListener 不兼容?

javascript - 为什么我的动态 javascript 高亮表单会损坏?

javascript - 前端开发人员面试编码问题 : a not defined and b is defined?

javascript - 谷歌登录弹出窗口不会持续很长时间或显示 "the requested action is invalid"

javascript - 使用 jQuery 的 Ajax 日历导航

PHP无法更新数据库,提交后没有任何反应

php - 根据数据库显示同一页面不同内容

javascript - 全局 JSON 变量

php - mac 使用 Homebrew 软件升级 native php,无法正常工作

php - 在 PHP 中使用 preg_match 通过多个分隔符拆分字符串