1

这是我正在构建的简单货币转换器的一些代码。脚本运行良好,calculate()clear()代码拒绝工作,而且看起来一样??

<a href="#" OnCLick="calculate();">US - CDN</a>
<a href="#" OnCLick="clear();">Clear</a>

<script type="text/javascript">
    function clear() {
            document.getElementById('us-cdn1').innerHTML = '';
    }
</script>
<script type="text/javascript">
    function calculate() {
        var amount = parseFloat(document.getElementById("amount").value);
        var result = document.getElementById("amount");
            result.value = (amount).toFixed(2);
        var result = document.getElementById("amount1");
            result.value = (amount * .9861932938856016).toFixed(2); 
            document.getElementById('us-cdn').innerHTML = 'US';
            document.getElementById('us-cdn1').innerHTML = 'CDN';
    }

</script>
4

1 回答 1

1

clear()是一个公共函数。将其更改为:

<a href="#" onclick="clearField();">Clear</a>

<script type="text/javascript">
function clearField() {
        document.getElementById('us-cdn1').innerHTML = '';
}
</script>
于 2013-02-03T18:02:05.240 回答