0
我有一個代碼,我希望在用戶鍵入textfield
中的某些內容後按下回車鍵,屏幕上會顯示他輸入的內容。但我無法做到這一點,我想在這裏得到一些幫助。顯示用戶在主體中鍵入的內容
<!DOCTYPE html>
<html>
<head>
<title>Tasks for the day</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
alert("When you have finished your task you only have to click on it.");
$(document).ready(function(){
$("p").click(function(){
$(this).hide();
});
});
$(document).keypress(function(e) {
if(e.which == 13) {
}
});
function showMsg(){
var userInput = document.getElementById('userInput').value;
document.getElementById('userMsg').innerHTML = userInput;
}
</script>
</head>
<body>
<h1>Tasks to do</h1>
<p>Type what you need to do:</p>
<input type="input" id="userInput" onkeyup=showMsg() value="" />
<p id="userMsg"></p>
</body>
</html>
剛剛試過代碼,它的工作。這裏有什麼確切的問題?當他們按下輸入鍵清除屏幕上除了值之外的所有內容時,是否需要? – AmmarCSE
當用戶在框中鍵入內容時,他將按回車。當他按下輸入時,我希望屏幕上顯示的是輸入的內容。 –
是什麼? https://jsfiddle.net/v58ugsg5/ – AmmarCSE