【发布时间】:2019-12-05 17:32:46
【问题描述】:
我只是从一个应用程序中学习 jQuery。我的购物清单程序有问题。每当我添加一些价格时,它都会以字符串显示我的结果;就像我添加 5 和 7 一样,它会在文本框中显示“512”。但我想在每次用户添加或删除任何内容时更新它。
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
</head>
<body>
<h1>My Shopping List</h1>
<input type="text" placeholder="New item" id="item" />
<input type="number" placeholder="Price" id="price"/>
<button id="add">Add</button>
<ol id="mylist"></ol>
<div>Total = ₹<textarea id="cartTotal" placeholder="0" disabled></textarea></div>
</body>
这是我的脚本,
var priceTotal = 0;
$(function() {
$("#add").on("click", function() {
var val = $("#item").val();
var prc = parseInt($("#price").val());
priceTotal += prc;
$("textarea").append(priceTotal);
完整代码是here。我在任何地方都没有找到任何合适的答案。
【问题讨论】:
标签: jquery html jquery-selectors