你好我正在爲學校做一個項目,我需要做的東西計數+1和+5和-1和-5,但如果它達到0,我按下-1按鈕它將進入負面。如何設置增量最小值
我試圖
if("#total" < 0)
{
number = 0;
}
但它沒有工作
這是到目前爲止我的代碼:
$(document).ready(function()
{
$("#add_buttonplus").click(function() {
var $counter = $("#total");
$counter.val(Number($counter.val()) + 1);
});
});
$(document).ready(function() {
$("#add_buttonminus").click(function()
{
var $counter = $("#total");
$counter.val(Number($counter.val()) - 1);
}
});
$(document).ready(function()
{
$("#add_buttonplus2").click(function() {
var $counter = $("#total");
$counter.val(Number($counter.val()) + 5);
});
});
$(document).ready(function() {
$("#add_buttonminus2").click(function()
{
var $counter = $("#total");
$counter.val(Number($counter.val()) - 5);
});
});
我的HTML:
<html>
<head>
<!--Title of the Site-->
<title>
</title>
<!-- Extern CSS -->
<link rel="stylesheet" type="text/css" href="order.css">
<!-- Jquery -->
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<!-- Extern JavaScript -->
<script src="order.js" type="text/JavaScript"></script>
</head>
<body>
<h1>
Flower
</h1>
<div id='Flower'>
<a href="#" id="add_buttonplus1"></a>
<a href="#" id="add_buttonminus1"></a>
<p id="Flowertekst1">
Add 1 Kilo
</p>
<a href="#" onclick="" id="add_buttonplus2"></a>
<a href="#" onclick="" id="add_buttonminus2"></a>
<p id="Flowertekst2">
Add 5 Kilo
</p>
<p id="Flowertotaal">
Total:
</p>
<input type="text" value="1" id="total" readonly />
</div>
</body>
</html>
你可以發表你的HTML –
當然我會在第二個 – Napokue
*中添加它「但它不起作用」*你期望的行爲是什麼,發生了什麼? 「不起作用」不是問題描述。 –