2017-02-06 5 views
0

私のジャバスクリプトに問題があります。ボタンのhtml機能として動作しているときは動作しません。問題のあるjavascript配列ですか?

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; 
}); 

誰かがこれを見て取り、おそらくそれと間違っているものを提案することができれば?

+2

が存在します。 * myFuntion *または* myFunction *はありません。 – RobG

+2

HTMLに引用符のタイプが間違っています。 '' 'や' ''ではなく、 '' 'や' ''を使用してください。コードを編集するときは、テキストエディタで "スマート引用符"をオフにしてください。 – Barmar

答えて

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

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

IDがBであり、getElementByIdを、それらのb変化1

あり、MyFunctionをdoesntのは `のonclick =「myFuntionを()」`削除

関連する問題