所以我試圖讓每次用戶提交輸入時清除文本輸入按回車。我試過$("#textbox").val('')
,但這不起作用,我不知道我做錯了什麼。我也試過.html('')
和.text('')
。我不知道爲什麼它不起作用。我不能得到.val('')來清除用戶輸入,我不知道爲什麼它不起作用
這是我的編碼。
// JavaScript Document
$(document).ready(function() {
$('a').click(function() {
$('#start').css('background-color', '#09C');
});
});
//Item variable//
$(document).ready(function() {
$("form").submit(function() {
var input = $("#command").val();
var check = false;
if (input == "help") {
$("#Help").clone().insertBefore("#placeholder").fadeIn(1000);
check();
}
if (input == "Lombardy East") {
$("<p class='text'> Great Choice! Close enough to Alexandra to have access to their commuters but far enough not to step on anyone's toes! Now it's time to choose your route. Shall we?</p>").hide().insertBefore("#placeholder").fadeIn(1000);
$("<p id='green' class='text'>Let's do this?</p>").hide().insertBefore("#placeholder").fadeIn(1000);
check();
check();
}
if (input == "Lyndhurst") {
$("<p class='text'> It's good enough choice. As long as you don't clash with other drivers on the main road, you should be fine. Now it's time to choose your route. Shall we?</p>").hide().insertBefore("#placeholder").fadeIn(1000);
$("<p id='green' class='text'>Okay?</p>").hide().insertBefore("#placeholder").fadeIn(1000);
check();
check();
}
if (input == "Orange Grove") {
$("<p class='text'>Hmmm ... That's a bit close to Louis Botha main road. You might have a few aggressive run ins. Good Luck with that.Now it's time to choose your route. Shall we?</p>").hide().insertBefore("#placeholder").fadeIn(1000);
$("<p id='green' class='text'>Sure?</p>").hide().insertBefore("#placeholder").fadeIn(1000);
check();
check();
}
if (input == "No") {
$("<p class='text'> Voetsak! Don't be a wuss!</p>").hide().insertBefore("#placeholder").fadeIn(1000);
check();
}
if (input == "Yes") {
var url = "thirdpage.html";
$(location).attr('href', url);
check();;
}
if (input == "Let's do this") {
var url = "frthpage.html";
$(location).attr('href', url);
check();
}
if (input == "Okay") {
var url = "ffthpage.html";
$(location).attr('href', url);
check();
}
if (input == "Sure") {
var url = "sxthpage.html";
$(location).attr('href', url);
check();
} else if (input != "Lombardy East") {
$("<p class='text'> I do not understand your answer</p>").hide().insertBefore("#placeholder").fadeIn(1000);
check();
}
$('#command').val("");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="placeholder"></div>
<form onsubmit="return false" autocomplete="off">
<input type="text" size="50" autofocus="autofocus" id="command" />
</form>
「我試過$(」 #文本框 「)VAL( '')。」 - >不是輸入的識別碼你的html代碼。 –
由於'check'是'FALSE',代碼將拋出一個錯誤,並在第一個'檢查();'遇到,從來沒有得到儘可能'$(「#指令」)VAL(「」);' 。 –