0

JavaScript でラジオ ボタンを検証しようとしていますが、これが私のコードです。

if (document.ExamEntry.GCSE.checked == true) {
    confirm("You have selected GCSE. Is this correct?");
}
if (document.ExamEntry.AS.checked == true) {
    confirm("You have selected AS. Is this correct?");
}
if (document.ExamEntry.A2.checked == true) {
    confirm("You have selected A2. Is this correct?");
}

確認ウィンドウが表示され、[送信] をクリックすると次のページに正常に移動しますが、キャンセル ボタンが機能していないようです。あなたのオプション。

結果を返すなどのことを試しました。結果 = false

それらは機能しないか、機能する場合はその逆であるため、同じページに留まるとキャンセルボタンが機能しますが、これは送信ボタンでも発生します.

4

3 に答える 3

3

confirmのドキュメントを確認してください。それは言う、

result は、OK またはキャンセルが選択されたかどうかを示すブール値です (true は OK を意味します)。

つまり、各行で戻り値をチェックする必要があります。これを行う簡潔な方法は、たとえば次のとおりです。

if (!confirm("You have selected A2. Is this correct?")) {
    // event.cancel = true, or whatever you need to do on your side to cancel
} // otherwise fall through and do what you're doing.

の戻り値を見たことがないため、現在のように、confirm常に「成功」​​のケースに陥ります。

于 2013-12-11T21:55:45.360 に答える
0
if (document.ExamEntry.GCSE.checked == true) { 
    if(confirm("You have selected GCSE. Is this correct?")) {
        // do something
    }
} if (document.ExamEntry.AS.checked == true) {
    if(confirm("You have selected AS. Is this correct?")) {
        // do something
    }
}  
if (document.ExamEntry.A2.checked == true) {
    if(confirm("You have selected A2. Is this correct?")) {
        //do something
    }
}
于 2013-12-11T21:57:17.663 に答える