【问题标题】:problematic javascript array?有问题的javascript数组?
【发布时间】:2017-06-23 22:15:29
【问题描述】:

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

如果有人可以看看这个并可能提出它有什么问题?

【问题讨论】:

  • 删除onclick=“myFuntion()”。没有 myFuntionmyFunction
  • 您的 HTML 中有错误的引号类型。使用'",而不是。编辑代码时关闭文本编辑器中的“智能引号”。

标签: javascript html arrays sorting


【解决方案1】:
<button id = “ButtonTwo” onclick=“myFunction()”>Count the Number of products!</button>

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

id 是 B,getElementById 是 b 改变其中之一

而且 myFunction 不存在

【讨论】:

    猜你喜欢
    • 2011-05-04
    • 1970-01-01
    • 1970-01-01
    • 2021-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-06
    • 1970-01-01
    相关资源
    最近更新 更多