JavaScript指南

JavaScript指南,javascript,html,Javascript,Html,我想有人帮我解决一个问题。目前,我的代码的第二部分不起作用(我将用两颗星标记它)。我希望它将第二个列表更改为第二个列表的长度,而不是相反。我真的很感激你的帮助 <!DOCTYPE html> <html> <body> <p>Uh-Oh the items are not in alphabetical order can you fix it!</p> <button onclick="myFunction()">Try

我想有人帮我解决一个问题。目前,我的代码的第二部分不起作用(我将用两颗星标记它)。我希望它将第二个列表更改为第二个列表的长度,而不是相反。我真的很感激你的帮助

<!DOCTYPE html>
<html>
<body>
<p>Uh-Oh the items are not in alphabetical order can you fix it!</p>
<button onclick="myFunction()">Try To Fix It</button>
<p id="Items"></p>
<script>
    var Devices = ["Printer", "Router", "Tablet", "Speakers", "Bluetooth Mouse"]
    document.getElementById("Items").innerHTML = Devices;
    function myFunction() {
    Devices.sort();
    document.getElementById("Items").innerHTML = Devices;

        }
        </script>
<p>Oh-No I Cant read but i know numbers how much does that list contain </p>
<button onclick="dosfunction()">Find The Length</button>
<p id="Count"></p>
<script>
        var Devices2 = ["Printer", "Router", "Tablet", "Speakers", "BluetoothMouse"]
        document.getElementById("Count").innerHTML = Devices2.length;
        function dosfunction () {
            Devices2.length;
            document.getElementById("Count").innerHTML = Devices2;

        }
        </script>
</body>
</html>

哦,这些东西不是按字母顺序排列的,你能修好吗

试着修复它

var设备=[“打印机”、“路由器”、“平板电脑”、“扬声器”、“蓝牙鼠标”] document.getElementById(“Items”).innerHTML=设备; 函数myFunction(){ Devices.sort(); document.getElementById(“Items”).innerHTML=设备; } 哦,不,我看不懂,但我知道那个列表包含多少数字

找出长度

var Devices2=[“打印机”、“路由器”、“平板电脑”、“扬声器”、“蓝牙鼠标”] document.getElementById(“Count”).innerHTML=Devices2.length; 函数dossfunction(){ 装置2.长度; document.getElementById(“Count”).innerHTML=Devices2; }

更清楚地说。。当我运行脚本时,我希望它显示列表,然后一旦按下按钮,我希望它显示列表中的项目数。目前,它正在以相反的方式进行操作。

这应该会起作用

<p>Uh-Oh the items are not in alphabetical order can you fix it!</p>
<button onclick="myFunction()">Try To Fix It</button>
<p id="Items"></p>
<script>

    var Devices = ["Printer", "Router", "Tablet", "Speakers", "Bluetooth Mouse"]
    document.getElementById("Items").innerHTML = Devices;
    function myFunction() {
    Devices.sort();
    document.getElementById("Items").innerHTML = Devices;

        }
        </script>
<p>Oh-No I Cant read but i know numbers how much does that list contain </p>
<button onclick="dosfunction()">Find The Length</button>
<p id="Count"></p>
<script>
    var Devices2 = ["Printer", "Router", "Tablet", "Speakers", "BluetoothMouse"]
    document.getElementById("Count").innerHTML = Devices2;
    function dosfunction () {
        document.getElementById("Count").innerHTML = Devices2.length;
    }
</script>

在这里,我交换了Devices2和Devices2.length,我发现唯一的问题是您的
dosfunction()

试试这个:

<!DOCTYPE html>
<html>
<body>
<p>Uh-Oh the items are not in alphabetical order can you fix it!</p>
<button onclick="myFunction()">Try To Fix It</button>
<p id="Items"></p>
<script>
   var Devices = ["Printer", "Router", "Tablet", "Speakers", "Bluetooth Mouse"]
   document.getElementById("Items").innerHTML = Devices;
   function myFunction() {
   Devices.sort();
   document.getElementById("Items").innerHTML = Devices;

    }
</script>
<p>Oh-No I Cant read but i know numbers how much does that list contain </p>
<button onclick="dosfunction()">Find The Length</button>
<p id="Count"></p>
<script>
    var Devices2 = ["Printer", "Router", "Tablet", "Speakers", "BluetoothMouse"]

    function dosfunction () {
       document.getElementById("Count").innerHTML = Devices2.length;

    }
</script>
</body>
</html>

哦,这些东西不是按字母顺序排列的,你能修好吗

试着修复它

var设备=[“打印机”、“路由器”、“平板电脑”、“扬声器”、“蓝牙鼠标”] document.getElementById(“Items”).innerHTML=设备; 函数myFunction(){ Devices.sort(); document.getElementById(“Items”).innerHTML=设备; } 哦,不,我看不懂,但我知道那个列表包含多少数字

找出长度

var Devices2=[“打印机”、“路由器”、“平板电脑”、“扬声器”、“蓝牙鼠标”] 函数dossfunction(){ document.getElementById(“Count”).innerHTML=Devices2.length; }
问题是,您必须交换这些..innerHTML代码-->

因此,代码的第二部分必须是:

<script>
var Devices2 = ["Printer", "Router", "Tablet", "Speakers", "BluetoothMouse"]
        document.getElementById("Count").innerHTML = Devices2;

        function dosfunction () {
            document.getElementById("Count").innerHTML = Devices2.length;
        }

</script>

var Devices2=[“打印机”、“路由器”、“平板电脑”、“扬声器”、“蓝牙鼠标”]
document.getElementById(“Count”).innerHTML=Devices2;
函数dossfunction(){
document.getElementById(“Count”).innerHTML=Devices2.length;
}
以下步骤:

var设备=[“打印机”、“路由器”、“平板电脑”、“扬声器”、“蓝牙鼠标”];
document.getElementById(“innerData”).innerHTML=设备;
函数myFunction(){
document.getElementById(“Items”).innerHTML=Devices.length;
document.getElementById(“innerData”).innerHTML=设备;
}
单击按钮创建数组,然后显示其长度

试试看


根据我的经验,“不工作”通常意味着代码触发了JavaScript错误,但作者不知道显示此信息的JavaScript控制台。您是否检查过这样的控制台?您是否尝试了
Devices2.length
而不是最后一行中的
Devices2
<script>
var Devices2 = ["Printer", "Router", "Tablet", "Speakers", "BluetoothMouse"]
        document.getElementById("Count").innerHTML = Devices2;

        function dosfunction () {
            document.getElementById("Count").innerHTML = Devices2.length;
        }

</script>