在Chrome中按下后退按钮时

在Chrome中按下后退按钮时

本文介绍了在Chrome中按下后退按钮时,单选按钮选择问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有16个 radio 按钮,它们是一个调查的两个问题的一部分(每个问题8个按钮).回答完两个问题后, php 会重定向到相同的下一页,依此类推,以此类推.

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.

当在浏览器中按下后退按钮时,我希望前面的两个答案仍能被选中.在Chrome中,前两个答案中的一个始终保持为选中.在Safari中,先前的两个答案都保持选中状态,这正是我所期望的.这不是一个大问题,但是如果Chrome的行为方式相同,那将是一个很好的选择.我还确保两个缓存都被清空,等等.

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.

我昨天发布了一个相关问题,显示了我如何显示和验证 radio 按钮:

I posted a related question yesterday which shows how I am displaying and validating the radio buttons:

具有多组单选按钮的jQuery验证

如果这还不够,我可以发布更多代码.

If this is not sufficient, I can post more code.

推荐答案

您最可能需要做的就是使用$ _SESSION ['answer_1'] = 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

这篇关于在Chrome中按下后退按钮时,单选按钮选择问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 06:46