如何创建Alphabetizer程序?

时间:2017-05-03 21:23:57

标签: html arrays alphabetical

这就是我到目前为止 - 我可以帮助你获得" alphabetized"版本出现?我一直试图添加不同的东西,但我不确定应该留下什么以及应该去做什么。我可以获得一些如何解决这个问题的技巧吗?

  <!DOCTYPE html>
    <html>
    <head>
    <title> Alphabetizer</title>
    </head>

    <body>


    <script>
    <p id="words"></p>
    function sumbitFunction(); {
    var words = document.getElementById("words"); 
    var input= input.sort();
    words.textContent = input.join();
    }
    </script>  

    <form>
    <form id="inputText">
    <input type="text" name="text here" value="write here" size= 100 
    value=40>
   <input type="button" 
   onclick="sumbitFunction() " value="Go"
   </form>
   </body>
   </html>

1 个答案:

答案 0 :(得分:1)

你可以这样做:

https://jsfiddle.net/Lvd5ecqu/1/

 <html>
    <head>
        <title> Alphabetizer</title>
    </head>
        <script type="text/javascript">
            var submitFunction = function() {
            var words = document.getElementById("words").value.split(" ");
            var input = words.sort();
            document.getElementById("output").innerHTML = input.join();
            }
        </script>
    <body>
        <p id="output"></p>
        <form>
            <form id="inputText">
                <input id="words" type="text" name="text here" value="write here" size= 100 value=40>
                <input type="button" onclick="submitFunction() " value="Go" />
        </form>
    </body>
</html>