问题
I have 16 radio buttons that are part of two questions for a survey ( 8 buttons per question). When both questions have been answered, the php redirects to the next page which is identical, and so on and so forth.
When the back button is pressed in the browser, I expected both previous answers to still be checked. In Chrome, one previous answer out of two always remains checked. In Safari, both previous answers remain checked, which is what I expected. Its not a huge problem, but it would be good if Chrome behaved the same way. I've also made sure both caches were emptied, etc.
I posted a related question yesterday which shows how I am displaying and validating the radio buttons:
JQuery Validation With Multiple Sets Of Radio Buttons
If this is not sufficient, I can post more code.
回答1:
Most likely what you need to do is track each question's answers using something like $_SESSION['answer_1'] = 1;
Then you need to make sure your browsers do not control the form's state by disabling autocomplete:
<form action="some_file.php" method="post" autocomplete="off">
And then all you need to do is add this in your forms:
<Input type='radio' name='question1choice1' value= '1' <?=(($_SESSION['answer_1' == 1) ? 'checked' : 'unchecked');?>Choice 1
<Input type='radio' name='question1choice2' value= '2' <?=(($_SESSION['answer_1' == 2) ? 'checked' : 'unchecked');?>Choice 2
来源:https://stackoverflow.com/questions/27132965/radio-button-selection-issue-when-the-back-button-is-pressed-in-chrome