在下面的HTML中,我试图逐个显示问题。问题数组来自json并包含所有问题对象。我使用Eclipse PDT和wamp服务器。当我在我的eclipse浏览器中运行以下代码时,问题之间的导航工作正常。但是当我在谷歌浏览器中运行相同的代码时,也可以点击其他每个按钮来调用提交按钮操作。我发现它使用的是chrome开发工具。
$(document).ready(function()
{
$.getJSON('http://localhost/3s/Sample/JsonCreation.php', function(data)
{
questionsArray = data;
displayQuestionJS(questionsArray[currentQuestionNo], document);
});
$('form').on('submit', function(event)
{
event.preventDefault();
$('#sampleDiv').load("UserReport.html");
});
});
$(document).on('click', 'button', function()
{
if ($(this).attr('id') == "markForReview" || $(this).attr('id') == "nextQuestion")
{
//NAVIGATION FOR NEXT QUESTION
currentQuestionNo++;
//RESETTING OPTIONS
$("input:radio").prop('checked', false);
}
else if ($(this).attr('id') == "clearResponse")
{
$("input:radio").prop('checked', false);
}
else
{
//RESETTING OPTIONS
$("input:radio").prop('checked', false);
currentQuestionNo = ($(this).attr('id') - 1);
}
displayQuestionJS(questionsArray[currentQuestionNo], document);
});
function displayQuestionJS(currentQuestion, document)
{
document.getElementById('questionNumber').innerText = currentQuestion.questionNumber;
document.getElementById('questionDescription').innerText = currentQuestion.quesDesc;
$('label[for=optionA]').html(currentQuestion.optionA);
$('#optionA').attr('value','A');
$('label[for=optionB]').html(currentQuestion.optionB);
$('#optionB').attr('value','B');
$('label[for=optionC]').html(currentQuestion.optionC);
$('#optionC').attr('value','C');
}
</script>
HTML
<div id="sampleDiv">
<br />
<br />
<form method="post" name="formQuestion">
<label id="questionNumber"></label>.
<label id="questionDescription"></label> <br />
<input type="radio" id="optionA" name="options"> </input> <label for="optionA"></label> <br />
<input type="radio" id="optionB" name="options"> </input> <label for="optionB"></label> <br />
<input type="radio" id="optionC" name="options"> </input> <label for="optionC"></label> <br />
<button id="markForReview">Mark for Review and Next</button>
<button id="clearResponse">Clear Response</button>
<button id="nextQuestion">Save and Next</button>
<br />
<br />
<input type="submit" id="submitButton" name="submitTest" value="Submit"></input>
</form>
</div>
请告诉我应该做些什么...