【发布时间】:2016-02-18 08:50:30
【问题描述】:
您好,当我按下回车键时,我正在尝试运行一个 javascript 函数。
到目前为止,这是我的代码
我的 HTML
<!DOCTYPE html>
<html>
<head>
<title>JS Bin</title>
</head>
<body>
<div>
<form id="inputForm">
<label for="userInput">Input : </label>
<span id="userInputSpan">
<input type="text" id="userInput" onkeydown="readInput(this)" />
</span>
</form>
</div>
</body>
</html>
我的 JAVASCRIPT
function readInput(e) {
if (e.keyCode == 13) { // 13 is enter key
// Execute code here.
// var temp = e.value;
// console.log(temp);
alert(e.value);
}
}
这是我的JSBin
【问题讨论】:
-
@KevalBhatt 不幸的是,我不允许使用 Jquery。 .如果允许我使用 Jquery,它会让生活变得更轻松:(
-
不允许使用jquery是什么原因?
-
@MorganGreen 这只是分配要求 :) 我被这个问题困住了,因此我问了 :)
标签: javascript html