[英]I have my code running on jsfiddle, but why can't on local computer?
As the title said, this is my code running on jsfiddle: http://jsfiddle.net/paopaomj/zgGpN/ 正如标题所说,这是我在jsfiddle上运行的代码: http : //jsfiddle.net/paopaomj/zgGpN/
and I copy all the code on my local computer (edit with brackets),but failed to run, something I miss? 我复制了我本地计算机上的所有代码(用括号编辑),但没能运行,我想念的东西? (ignoring the css style here)
(忽略这里的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>
use either, 用其中之一,
$(document).ready(function() {
// Handler for .ready() called.
});
or 要么
$(function() {
// Handler for .ready() called.
});
instead of 代替
$document.ready(function(){
// Handler for .ready() called.
});
Use command function like this, 使用这样的命令功能,
$("#command").on('keyup', function (e) {
if (e.keyCode == 13) {
submit();
}
});
I've corrected your code (wrong instruction for "document ready" and formatting) 我已经更正了你的代码(错误的说明“文件就绪”和格式化)
<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>
Your syntax was incorrect around document.ready()
ie $(document).ready(function(){
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.