正如标题所说, 这是我在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>
答案 0 :(得分:2)
使用其中之一,
$(document).ready(function() {
// Handler for .ready() called.
});
或
$(function() {
// Handler for .ready() called.
});
而不是
$document.ready(function(){
// Handler for .ready() called.
});
答案 1 :(得分:0)
使用这样的命令功能,
$("#command").on('keyup', function (e) {
if (e.keyCode == 13) {
submit();
}
});
答案 2 :(得分: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>
答案 3 :(得分: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>