有问题的javascript数组?

时间:2017-02-06 20:35:43

标签: javascript html arrays sorting

我的javascript问题。当作为按钮的html函数运行时不起作用。

HTML:

<p>Click the button to sort the array.</p>
<button id=“buttonOne” onclick=“myFuntion()”>Try it</button>

<p id="demo"></p>
<button id = “ButtonTwo” onclick=“myFunction()”>Count the Number of products!</button>

<p id=‘demo2”></p>

JavaScript的:

var fruits = ["apple", "banana", "mango", "orange","avocado"];
document.getElementById("demo").innerHTML = fruits;

var buttonOne = document.getElementById("buttonOne");
var buttonTwo = document.getElementById("buttonTwo");

buttonOne.addEventListener("click", function() {
    fruits = fruits.sort();
    document.getElementById("demo").innerHTML = fruits;
});

buttonTwo.addEventListener("click", function() {
    length = fruits.length;
    document.getElementById("demo2").innerHTML = length;
});

如果有人可以看看这个并且可能暗示它出了什么问题?

1 个答案:

答案 0 :(得分:0)

<button id = “ButtonTwo” onclick=“myFunction()”>Count the Number of products!</button>

var buttonTwo = document.getElementById(“buttonTwo”);

id为B,getElementById为b,更改其中一个

myFunction不存在