私はMagic 8 Ballページを作成しています。私のページのSubmitボタンをクリックするたびに、#eightBallAnswerのテキストが私のランダムな回答の1つに数秒間変化してから変更されます私のHTMLの元のテキストに戻ります。私は複数のブラウザでこれを試しました。いくつかの洞察は大いに感謝されるだろう。clickイベントでjQueryで要素のテキストを変更します。後で瞬時に変更する
は、ここに私のjQueryのです:のは、フォームが提出し、さわやかなページ:)
使用される原因と
$(document).ready(function(){
$("#submit").click(function() {
//List of possible responses
var response = ["Ask again later…", "Yes", "No", "It appears so", "Reply is hazy, please try again", "Yes, definitely", "What is it you really want to know?", "Outlook is good", "My sources say no", "Signs point to yes", "Don't count on it", "Cannot predict now", "As I see it, yes", "Better not tell you now", "Concentrate and ask again"];
//generate a random number between 0-14
var randomNumber = Math.floor(Math.random() * 15);
//Present random answer
$("#eightBallAnswer").text(response[randomNumber]);
});
});
'
ありがとうございました!これもうまくいき、簡単にするためにあなたのソリューションに行ってきました。フォームタグに含まれていない入力でもHTML5の検証がうまくいくことがわかります。驚くばかり! – thenomadicmann