我正在编写一个简单的脚本,除了如何为输出设置默认值之外,几乎已经弄清楚了。如何让“总计”显示默认值 0,例如页面加载时?谢谢!
<!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>