【问题标题】:Trouble displaying multidimensional array in a div无法在 div 中显示多维数组
【发布时间】:2017-04-14 03:09:01
【问题描述】:

Expected Output 我希望单击按钮时数字看起来像一个矩阵,我不知道如何使用多维数组来获得预期的输出(单击蓝色链接)。有什么帮助吗?

<!DOCTYPE html>
<html>
<body>

<div class="rightDiv">
<div id = "pastcalcblock"> 
    <h3> PAST CALCULATIONS </h3>
         <input type = "text" size = "1" id = "text1"/>
         <input type = "text" size = "1" id = "text2"/>
         <input type = "text" size = "1" id = "text3"/>
         <input type = "text" size = "1" id = "text4"/><br>
         <input type = "button" value = "Ok" id = "operation" onClick = "display()"/>
         <div id = "resultTab">
                SORT<br>
                    <input type = "button" value = "As Entered" id = "enteredBut">
                    <input type = "button" value = "By Result" id = "resultBut"><br><br>
                    <div id = "expressions"></hr></div>                 
            </div>
        </div>

<script>
function display()
{
    var arrayOne =  [document.getElementById('text1').value,document.getElementById('text2').value,document.getElementById('text3').value,document.getElementById('text4').value ][];


    document.getElementById("expressions").innerHTML = arrayOne;
    var para = document.createElement("P");
    var t = document.createTextNode("arrayOne");
    para.appendChild(t);
    document.getElementById("expresions").appendChild(para);
}

</script>

</body>
</html>

【问题讨论】:

    标签: javascript html arrays loops sorting


    【解决方案1】:

    只更正不带[]的arrayOne

    JSFiddle

    【讨论】:

    • 我希望数组看起来像一个矩阵。我该怎么做?
    • 一个好的矩阵作为你的图像,等于你的例子,只有“表达式”有一个错误是“表达式”这里有正确的例子JsFiddle
    • 1 2 3 4 1 1 1 1
    • 不,看最后更新的小提琴是作为一个矩阵,JsFiddle updated
    • 非常感谢您的帮助!我之前没看到文件。
    猜你喜欢
    • 2013-12-11
    • 2016-04-05
    • 2011-06-09
    • 1970-01-01
    • 2018-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多