单选按钮及其值的 PHP 语法和结构
单选框代码:
<input
type = "radio"
name = "choice"
value = "A" />Apples />
<input
type = "radio"
name = "choice"
value = "B" />Oranges<br />
$choice=array("A"=>1.00, "B"=>0.80);
echo $choice["A"]; // will give me the value of 1.00
echo $choice["B"]; // will give me the value of 0.80
给定上面的代码片段,HTML 单选框、数组或选择是否有问题?
Radio box code:
<input
type = "radio"
name = "choice"
value = "A" />Apples />
<input
type = "radio"
name = "choice"
value = "B" />Oranges<br />
$choice=array("A"=>1.00, "B"=>0.80);
echo $choice["A"]; // will give me the value of 1.00
echo $choice["B"]; // will give me the value of 0.80
Given the code snippet above, is there anything wrong in terms of either the HTML radio box, the array or the choices?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,看起来很好。
除了苹果文本后面的随机
/>
之外,但我怀疑这是一个拼写错误?您可能还想考虑这一点。大概你正在走向什么? :)
这将是接收您的无线电选择的代码。它确保选择有效,然后打印它。
Nope, that looks perfectly fine.
Except for the random
/>
after your Apples text, but I suspect this is a typo?You may also want to consider this. Probably what you are heading towards? :)
This would be the code that receives your radio choice. It makes sure the choice is valid and then prints it.
据我理解你的问题,PHP 代码似乎是错误的。您尚未在 html 代码中指定使用 [ ] 完成的数组。
这就是您在 php 代码中执行的操作,以回显单选的选择:
这将回显选定的单选按钮值 A 或 B。
As far as i understood your question, PHP Code seems to be wrong. You have not specified an array in your html code which is done using [ ].
This is what you do in you php code to echo the selection of the radio:
This will echo selected radio buttons value either A or B.
我不确定您想要实现什么目标,但有几件事需要您注意。
首先,检查
的语法:http: //www.w3schools.com/html/html_forms.asp
所以我将你的html代码更改为:
在服务器端,实际提交表单后,只需查找
$_POST[ "choice" ]
为您想要的值(1.00 或 0.80)。I'm not sure what are you trying to achieve, but there are several things that need your attention.
First of all, check the syntax of
<input>
: http://www.w3schools.com/html/html_forms.aspSo I'd change your html code to:
And on server side, after actually submitting the form, just look for
$_POST[ "choice" ]
for your desired value (1.00 or 0.80).