Javascript,无法弄清楚代码无法正常工作的原因

时间:2015-03-07 02:59:29

标签: javascript percentage

body


<form>I want to know the
<select id="birthdeath">
    <option value="birth">birth rate</option>
    <option value="death">death rate</option>
</select>
<p></p>of  
<select id="country">
    <option value="neth">Netherlands</option>
<option value="ger">Germany</option>
    <option value="france">France</option>
    <option value="bras">Brasil</option>
</select>
in: <input type="text" maxlength="3" size="3" id="years" placeholder="21"/> years

    <p></p>
    <input id="calculate" type="button" value="calculate!" />
</form>
<p>&nbsp;</p>
<div id="div2">The birth or death rate of your country will be ... </div>
</div>
</div>


  <script type="text/javascript">
var number = {
    birth: {
        neth: 11,
        france: 13,
    ger:8,
        bras: 17,
    },
    death: {
        neth: 8,
        france: 9,
        ger: 11,
    bras: 6,
    }
};



document.getElementById('calculate').addEventListener('click', function () {
    var birthdeath = document.getElementById('birthdeath').value;
    var nationality = document.getElementById('country').value;

    var new = new [birthdeath][nationality] 
    var total=Math.round(new*1.10)

    document.getElementById('div2').innerHTML = "The birth/ death rate of your country will be <b>" + total + "</b>.";
}, false);</script>

  </body>

1 个答案:

答案 0 :(得分:1)

它有点错误......你不能为一个保留字命名一个var new。

其次,您在表单开始标记后生成随机文本。但在任何元素之前。

在你的&#34;新&#34; var创建我不确定你要用[] []创建什么,但这并不意味着。

第四个不确定你的代码是否被剪切但是底部附近还有两个不匹配的结束div用于脚本