我使用下面的代码在表单提交后保留单选按钮选择,但在表单提交后它不断重置为最后一个按钮
<input type="radio" name="button" value="Yes" <?php if(isset($_POST['button']) == 'Yes') echo ' checked="checked"';?> />Yes
<input type="radio" name="button" value="No" <?php if(isset($_POST['button']) == 'No') echo ' checked="checked"';?> />No
我怎样才能保留选择?
isset() http://php.net/manual/en/function.isset.php返回一个boolean http://php.net/manual/en/language.types.boolean.php。因此,直接比较Yes
/No
不是你想要的。
你想要的是:
if (isset($_POST['button']) && $_POST['button'] == 'Yes')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)