选中哪个单选按钮?

2024-02-19

我想检查哪个单选按钮被选中。然后,在我问这个问题之前,我查看了这里的问题,他们说代码

        if(document.getElementById('number1').checked) 

就是答案。但是,我收到错误“使用未定义的常量文档 - 假定‘文档’”并且

Call to undefined function getElementById().

哪里出了问题?我必须写这个函数吗getElementById('number1').checked因为它说“未定义”? 谢谢


你的代码是Javascript。要检查 PHP 中单选按钮的值,它需要有一个name属性,以 GET 或 POST 形式发送。

// If form method='get'
if (isset($_GET['name_of_radio_group'])) {

  // Show the radio button value, i.e. which one was checked when the form was sent
  echo $_GET['name_of_radio_group'];
}

// If form method='post'
if (isset($_POST['name_of_radio_group'])) {

  // Show the radio button value, i.e. which one was checked when the form was sent
  echo $_POST['name_of_radio_group'];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

选中哪个单选按钮? 的相关文章

随机推荐