单选按钮选中属性
我如何知道 PHP 中的单选按钮检查属性是否为 true,有人可以给我一个例子吗?
谢谢..
How can I know if the radio button checked property is true in PHP, can anyone give me an example?
Thanks..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
提交表单后,在 $_POST (或 $_GET 分别)中,您将拥有一个包含单选按钮名称的键和包含单选按钮值的值(如果已选中)。否则根本就不会有这样的钥匙。
所以
将产生
$_POST['test'] == 'checked!'
After submitting your form, in $_POST (or $_GET respectively) you'll have a key with your radio button name and value with your radio button value, if it was checked. Otherwise, there will be no such key at all.
So
<input type="radio" name="test" value="checked!" checked="checked" />
Will produce
$_POST['test'] == 'checked!'
您可以尝试询问checked属性,请参见示例:
然后在php中获取raddio按钮的值: $publicar=$postvars['publicar']; 并按顺序询问其值知道它是 TRUE 还是 FALSE
另外,如果你想使用 javascript 操作这些值:
注意:$postvars=$_POST
You can try to ask for the checked attribute, see the example:
Then get the value of the raddio button in php: $publicar=$postvars['publicar']; and ask for its value in order to know if it is TRUE or FALSE
In addition, if you want to manipulate the values using javascript:
Note: $postvars=$_POST
如果您的复选框被选中,它将由 $_POST 或 $_GET 数组中的
key=>value
对表示。因此,如果您希望布尔值知道它是否已选中,请使用以下命令:如果您想要复选框的实际值:
将 $_POST 替换为 $_GET,具体取决于表单的方法。
If your checkbox is checked, it is represented by a
key=>value
pair in your $_POST or $_GET array. So, if you want a boolean to know if it's checked or not use this:If you want the actual value of the checkbox:
Replace $_POST with $_GET, depending on the method of your form.
这取决于您的单选按钮
名称
例如,如果您有 2 个带有
name = 'gender'
的单选按钮,并且选中了带有value='male'
的单选按钮,那么在 PHP 中您将拥有$_POST['gender']
等于male
(或 $_GET 与 GET)It depends of your radio button
name
For example, if you got 2 radio buttons with
name = 'gender'
and you checked the one withvalue='male'
, you'll have in PHP$_POST['gender']
equals tomale
(or $_GET with GET)