未选中时需要设置无线电组的默认值

Ash*_*win 4 html javascript forms post

在我的html表单中,我有一组单选按钮

<form action="receive.php" method="post">
    <input type="radio" name="rad" value="one" /> One <br />
    <input type="radio" name="rad" value="two" /> Two <br />
    <input type="radio" name="rad" value="three" /> Three <br />
    <input type="submit" value="submit" />
</form>
Run Code Online (Sandbox Code Playgroud)

我有一个没有选中单选按钮的场景.在这种情况下,我的服务器端php接收输入值为false.我想做的是将false更改为nullundefined.那可能吗?任何帮助是极大的赞赏.

小智 6

你可以这样做:

<form action="receive.php" method="post">
    <input type="radio" name="rad" value="one" /> One <br />
    <input type="radio" name="rad" value="two" /> Two <br />
    <input type="radio" name="rad" value="three" /> Three <br />
    <input type="hidden" name="rad" value="null" />
    <input type="submit" value="submit" />
</form>
Run Code Online (Sandbox Code Playgroud)

现在,如果您没有选中任何单选按钮,您将获得"null"输入值,但请记住"null"NULLPHP中的不同.