邮资计算器未在IE中输出

时间:2014-07-25 12:08:25

标签: javascript html internet-explorer

我在使用Javascript创建的邮资计算器时遇到了一些麻烦,它需要一个数量并创建一个变量,乘以一个定义的数字(即邮资费用),然后输出总数(所有变量的总和)。它在除IE之外的所有浏览器中都能完美运行,这让我相信问题不在于JavaScript,而在于HTML。我认为我已将问题缩小到<output>标记,但我已尝试将其与<span>进行交换,但问题仍然存在:

<html>
<head>
<script type="text/javascript">
function calculate() {
        var let1 = document.getElementById('let1').value;   
        var let1f = let1 * 0.12;        
        var let2 = document.getElementById('let2').value;   
        var let2f = let2 * 0.16;        
        var ll1 = document.getElementById('ll1').value; 
        var ll1f = ll1 * 0.17;      
        var ll2 = document.getElementById('ll2').value; 
        var ll2f = ll2 * 0.12;      
        var sp01 = document.getElementById('sp01').value;   
        var sp01f = sp01 * 0.30;        
        var sp02 = document.getElementById('sp02').value;   
        var sp02f = sp02 * 0.30;        
        var sp11 = document.getElementById('sp11').value;   
        var sp11f = sp11 * 0.30;        
        var sp12 = document.getElementById('sp12').value;   
        var sp12f = sp12 * 0.30;        
        var mp01 = document.getElementById('mp01').value;   
        var mp01f = mp01 * 0.85;
        var mp02 = document.getElementById('mp02').value;   
        var mp02f = mp02 * 0.80;
        var mp11 = document.getElementById('mp11').value;   
        var mp11f = mp11 * 1.4;
        var mp12 = document.getElementById('mp12').value;   
        var mp12f = mp12 * 1.15;
        var result = document.getElementById('result'); 
        result.value = parseFloat(let1f + let2f + ll1f + ll2f + sp01f +sp02f + sp11f +sp12f +mp01f + mp02f + mp11f + mp12f).toFixed(2);
    }
</script>
</head>
<body>
    <div class="calculator">
        <ul class="column" id="column1">
            <li class="topbar" id="format">Format</li>
            <li>Letters</li>
            <li>Large Letters</li>
            <li>Small Parcel (0-1kg)</li>
            <li>Small Parcel (1-2kg)</li>
            <li>Medium Parcel (0-1kg)</li>
            <li>Medium Parcel (1-2kg)</li>
            <li class="saving">Weekly Saving</li>
        </ul>
        <ul class="column" id="column2">
            <li class="topbar">First Class</li>
            <li><input id="let1" type="number" oninput="calculate()"/></li>
            <li><input id="ll1" type="number" oninput="calculate()"/></li>
            <li><input id="sp01" type="number" oninput="calculate()"/></li>
            <li><input id="sp11" type="number" oninput="calculate()"/></li>
            <li><input id="mp01" type="number" oninput="calculate()"/></li>
            <li><input id="mp11" type="number" oninput="calculate()"/></li>
            <li class="saving">=</li>
        </ul>
        <ul class="column" id="column2">
            <li class="topbar">Second Class</li>
            <li><input id="let2" type="number" oninput="calculate()"/></li>
            <li><input id="ll2" type="number" oninput="calculate()"/></li>
            <li><input id="sp02" type="number" oninput="calculate()"/></li>
            <li><input id="sp12" type="number" oninput="calculate()"/></li>
            <li><input id="mp02" type="number" oninput="calculate()"/></li>
            <li><input id="mp12" type="number" oninput="calculate()"/></li>
            <li class="result">&pound;<output id="result"/></li>
        </ul>
</div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

Internet Explorer(和Safari)不支持output标记 http://www.w3schools.com/tags/tag_output.asp

您可以在其中使用span。而不是设置result.value使用result.innerHTML