0

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

2 回答 2

1

把它扔到 HTML 中!

<div>Total<span id="multi">0</span><br></div>
于 2013-07-15T19:02:43.583 回答
0

我不确定你在问什么,但你不能这样做$('#multi').html('Total:' + total);吗?

于 2013-07-15T19:03:27.307 回答