单选按钮选中属性

发布于 2024-09-28 10:07:48 字数 61 浏览 0 评论 0原文

我如何知道 PHP 中的单选按钮检查属性是否为 true,有人可以给我一个例子吗?

谢谢..

How can I know if the radio button checked property is true in PHP, can anyone give me an example?

Thanks..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

素罗衫 2024-10-05 10:07:48

提交表单后,在 $_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!'

雪若未夕 2024-10-05 10:07:48

您可以尝试询问checked属性,请参见示例:

<label for="public0"><input type="radio" checked="checked" name="publicar" id="public0" value="TRUE" /> YES</label>
<label for="public1"><input type="radio" name="publicar" id="public1" value="FALSE" /> NO</label>

然后在php中获取raddio按钮的值: $publicar=$postvars['publicar']; 并按顺序询问其值知道它是 TRUE 还是 FALSE

另外,如果你想使用 javascript 操作这些值:

if ( $("public0").checked == true) 
{ ...} or if ( $("public1").checked == true){...}
 //alert($("public0").checked); //if you want to see the value
  //alert($("public1").checked);

注意:$postvars=$_POST

You can try to ask for the checked attribute, see the example:

<label for="public0"><input type="radio" checked="checked" name="publicar" id="public0" value="TRUE" /> YES</label>
<label for="public1"><input type="radio" name="publicar" id="public1" value="FALSE" /> NO</label>

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:

if ( $("public0").checked == true) 
{ ...} or if ( $("public1").checked == true){...}
 //alert($("public0").checked); //if you want to see the value
  //alert($("public1").checked);

Note: $postvars=$_POST

烙印 2024-10-05 10:07:48

如果您的复选框被选中,它将由 $_POST 或 $_GET 数组中的 key=>value 对表示。因此,如果您希望布尔值知道它是否已选中,请使用以下命令:

$checked = (isset($_POST['checkbox_name']))?true:false;

如果您想要复选框的实际值:

$checked = (isset($_POST['checkbox_name']))?$_POST['checkbox_name']:NULL;

将 $_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:

$checked = (isset($_POST['checkbox_name']))?true:false;

If you want the actual value of the checkbox:

$checked = (isset($_POST['checkbox_name']))?$_POST['checkbox_name']:NULL;

Replace $_POST with $_GET, depending on the method of your form.

如若梦似彩虹 2024-10-05 10:07:48

这取决于您的单选按钮名称
例如,如果您有 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 with value='male', you'll have in PHP $_POST['gender'] equals to male (or $_GET with GET)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文