0

正如标题所说,这是我在 jsfiddle 上运行的代码:http: //jsfiddle.net/paopaomj/zgGpN/

我复制了本地计算机上的所有代码(用括号编辑),但未能运行,我错过了什么?(这里忽略css样式)

    <html>
    <head>
        <script type="text/javascript" src="http://code.jquery.com/jquery-2.0.2.min.js"></script>
        <!--<script type="text/javascript" src="tools.js"></script>-->
        <link rel="stylesheet" type="text/css" href="style.css">
    </head>
    <body>
        <script>
            $document.ready(function(){
                $("#command").keyup(function (e) {
                    if (e.keyCode == 13) {
                        submit();
                    }
                });

                var submit = function () {
                    var commandEl = document.getElementById("command");
                    var command = commandEl.value;
                    var outputel = document.getElementById("output");
                    var new_row = document.createElement("div");
                    new_row.innerHTML = "root@host# > " + command;
                    outputel.appendChild(new_row);
                    commandEl.value="";
                };
            })
        </script>
        <div id="output"></div>
        <div id="input">
            root@host# >
            <input type="text" id="command" />
    </div>
</body>
</html>
4

4 回答 4

2

使用任何一个,

$(document).ready(function() {
   // Handler for .ready() called.
});

或者

$(function() {
    // Handler for .ready() called.
});

代替

$document.ready(function(){
    // Handler for .ready() called.
});
于 2013-08-28T08:55:46.690 回答
0

您的语法不正确,document.ready()$(document).ready(function(){

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<script type="text/javascript">
    $(document).ready(function(){
        $("#command").keyup(function (e) {
            if (e.keyCode == 13) {
                submit();
            }
        });
    });

var submit = function () {
        var commandEl = document.getElementById("command");
        var command = commandEl.value;
        var outputel = document.getElementById("output");
        var new_row = document.createElement("div");
        new_row.innerHTML = "root@host# > " + command;
        outputel.appendChild(new_row);
        commandEl.value="";
    };
</script>

<style type="text/css">
body {
    font-family:'Rosario', sans-serif;
    background-color: #000000;
    font-size: 16px;
    color: #00FF00;
}

#output { margin-bottom: 0px; background-color: #000000; }
#input { margin-top: 0px; background-color: #000000; }

input {
    border: 0;
    background: #000000;
    color: #00FF00;
    outline: none;
    font-family:'Rosario', sans-serif;
    font-size: 16px;
    padding: 0px;
    margin-left: -0.1px;
    margin: 0px;
}
</style>
</head>
<body>
    <div id="output"></div>
    <div id="input"> 
        root@host# >
        <input type="text" id="command" />
    </div>
</body>
</html>
于 2013-08-28T09:00:18.637 回答
0

像这样使用命令功能,

            $("#command").on('keyup', function (e) {
                if (e.keyCode == 13) {
                    submit();
                }
            });
于 2013-08-28T08:59:05.663 回答
0

我已经更正了您的代码(“文档准备就绪”和格式化的错误说明)

  <html>
    <head>
        <script type="text/javascript" src="http://code.jquery.com/jquery-2.0.2.min.js"></script>
        <!--<script type="text/javascript" src="tools.js"></script>-->
        <link rel="stylesheet" type="text/css" href="style.css">
                <script type="text/javascript">
            $(document).ready(function(){
                $("#command").keyup(function (e) {
                    if (e.keyCode == 13) {
                        submit();
                    }
                });

                var submit = function () {
                    var commandEl = document.getElementById("command");
                    var command = commandEl.value;
                    var outputel = document.getElementById("output");
                    var new_row = document.createElement("div");
                    new_row.innerHTML = "root@host# > " + command;
                    outputel.appendChild(new_row);
                    commandEl.value="";
                };
            })
        </script>
    </head>
    <body>

        <div id="output"></div>
        <div id="input">
            root@host# >
            <input type="text" id="command" />
    </div>
</body>
</html>
于 2013-08-28T08:59:07.260 回答