簡體   English   中英

表單提交后保持選中單選按鈕

[英]Keep radio button selected after a form submit

我使用下面的代碼在表單提交后保持單選按鈕選擇,但它在表單提交后繼續重置為最后一個按鈕

<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()返回一個boolean 因此,直接比較Yes / No不是您想要的。

你想要的是:

if (isset($_POST['button']) && $_POST['button'] == 'Yes')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM