输入的输入值将返回为undefined.我已经看到过这样的其他问题,但没有任何效果.无论如何,当我使用我的jQuery它总是给我undefined.
jQuery的:
$( document ).ready(function() {
$('#Input').keypress(
function(e){
if (e.keyCode == 13) {
alert( ">" + $("#Input").value );
}
});
}); Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html>
<style type="text/css">
body{
background-color: black;
color: #00c600;
font-family: VT323;
}
input{
background-color: black;
color: #00c600;
font-family: VT323;
border:none;
width: 98%%;
height: 30px;
font-size: 20px;
border: 2px black;
float: left;
margin-left: 10px;
list-style-type: none;
position: absolute;
bottom: 17px;
}
input:focus {
outline: 0;
}
h1{
text-align: center;
font-size: 50px;
}
h2{
padding-left: 20px;
}
::-webkit-input-placeholder {
color: #00c600;
}
::-webkit-scrollbar {
display: none;
}
</style>
<body>
<script src="http://code.jquery.com/jquery-1.3.2.min.js">
</script>
<script src="jquery.js">
</script>
<link href='http://fonts.googleapis.com/css?family=VT323' rel='stylesheet' type='text/css'>
<h1>FUN TIME BETA 0.1 </h1>
<div id="Text" style="overflow:auto; width:100%; height:400px;">
<h2>>Welcome to Fun Time</h2>
<h2>>Press F11 to enter full screen</h2>
</div>
<h3 style="float:left;list-style-type: none; position: absolute; bottom: 5px;">></h3>
<input name="Input" id="Input" type="text" autofocus> </input>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
当我提醒时,undefined.控制台日志undefined.追加,返回错误(错误无关紧要).我尝试多次更改代码.
value是本机DOM元素的属性,$('#Input')是一个jQuery对象,它们没有value属性,因此错误.
由于您在事件处理程序中执行代码,因此可以使用this.value或$(this).val()使用.
| 归档时间: |
|
| 查看次数: |
4369 次 |
| 最近记录: |