0
我正在研究一個簡單的腳本,除了如何設置輸出的默認值之外,幾乎已經弄明白了。如何讓「Total」顯示默認值0,就像頁面加載時一樣?謝謝!如何使用jQuery .html()設置默認輸出?
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> demo</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.10.2.js'></script>
<style type='text/css'>
#multi
{
margin-left:25px;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
$('input').on('keyup click',function(event){ // run anytime the value changes
var firstValue = parseInt($('#quantity').val()) || 0; // get value of field
var total = firstValue * 5; // multiply them together
$('#multi').html(total); // output it
});
});
</script>
</head>
<body>
<label for="quantity">Quantity</label>
<input type="number" id="quantity" min="0" max="250" size="3" value="0"/>
<div>Total<span id="multi"></span><br></div>
</body>
</html>
編輯:我的不好,非常感謝!這麼簡單,我現在覺得很愚蠢。大聲笑 –