此示例適用「檢查」,但給出「遺漏的類型錯誤:無法讀取屬性未定義的‘檢查’」&&沒有工作,遺漏的類型錯誤:無法讀取屬性未定義
但不與& &物業工作兩if語句
如果(X ==真)& &如果(j == 「正確」)
\t function myFunction(){
\t \t var question = document.getElementById("question-1");
\t \t var options = question.getElementsByTagName("input");
\t \t
\t \t for(var i=0;i<=options.length;i++){
\t \t \t
\t \t \t var x = options[i].checked;
\t \t \t var j = options[i].className;
// if(x == true) && if(j=="correct"){ - this does not work
\t \t \t if(x == true){
\t \t \t \t if(j=="correct"){
\t \t \t \t \t question.getElementsByClassName("result")[0].innerHTML = "Your answer is correct"; \t
\t \t \t \t }else{
\t \t \t \t \t question.getElementsByClassName("result")[0].innerHTML = "Your answer is wrong"; \t
\t \t \t \t }
\t \t \t } \t \t
\t \t }
\t };
\t <ul>
\t \t <div id="question-1">
\t \t \t <li>What is a Computer Bug?</li>
\t \t \t <input type="radio" name="selection" class="correct" onclick="myFunction()"><label>An error</label>
\t \t \t <input type="radio" name="selection" class="wrong" onclick="myFunction()"><label>A Moth</label> \t
\t \t \t <p class="result"></p>
\t \t </div>
\t </ul>
這不是如何與IFS &&工作。應該是if(x == true && j ==「correct」) –
謝謝。現在它可以工作 –