サイト内のボタンを押したときに、
jQueryのダイアログボックスを表示して
ダイアログボックスを閉じたときにjavascript内の
if (Qcnt == Question.length)を実行させたいのですが方法はありますか?
ダイアログボックス閉じたときの判定でjQuery('#dialog').dialog('isOpen')を
試したのですが正しい動かし方がわかりませんでした。
初歩的な質問ですがご回答お待ちしております。
jQuery
let Qcnt = 0; let Q = document.getElementById('_question'); // 問題を表示するオブジェクトを取得する let A1 = document.getElementById('_ans1'); let A2 = document.getElementById('_ans2'); let A3 = document.getElementById('_ans3'); let A4 = document.getElementById('_ans4'); let A5 = document.getElementById('_ans5'); let lst= document.getElementById('last'); var $button = document.querySelector('.button') // 正解数を保持する値 let Correct = 0; // 現在の問題数 let Qcnt2 // 問題を画面に表示する処理 function Q_Set() { Qcnt2=Qcnt Qcnt2=Qcnt2+1 Q.textContent = "問題"+Qcnt2+" : "+Question[Qcnt][0]; A1.textContent = Question[Qcnt][1]; A2.textContent = Question[Qcnt][2]; A3.textContent = Question[Qcnt][3]; A4.textContent = Question[Qcnt][4]; A5.textContent = Question[Qcnt][5]; lst.textContent=""; }; // 画面に表示 Q_Set(); // 回答ボタンを押したときの処理 function Answer_Check(ans) { var buttons = [ { text: "閉じる", click: function () { $(this).dialog('close'); } } ]; if(ans == Question[Qcnt][6]) { // ダイアログを表示 showDialog("回答", "正解! 答えは, "+ Question[Qcnt][6], buttons); Correct++; } else { // ダイアログを表示 showDialog("回答", "不正解! 答えは, "+ Question[Qcnt][6], buttons); } if (Qcnt2 == Question.length) { Q.textContent = "問題は以上です. 正解数は" + Correct + "でした!"; A1.textContent = ""; A2.textContent = ""; A3.textContent = ""; A4.textContent = ""; A5.textContent = ""; lst.textContent = "このページを再読み込みすると, 問題を再チャレンジできます! "; document.getElementById('btn').style.visibility = 'hidden'; } else { // 画面に表示 Qcnt++; Q_Set();}} function showDialog(title, message, buttons) { var html_dialog = '<div>' + message + '</div>'; $(html_dialog).dialog({ title: title, buttons: buttons, close: function() { $(this).remove();} }); }
まだ回答がついていません
会員登録して回答してみよう