html中name属性的有效值 [英] valid value for name attribute in html

查看:167
本文介绍了html中name属性的有效值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PHP从html页面获取单选按钮值。我的html看起来像这样:

 < input type =radioname =1.1value =yes> 
< input type =radioname =1.1value =no>

< input type =radioname =1value =yes>
< input type =radioname =1value =no>

结果是$ _POST ['1']返回值,但$ _POST ['1.1' ]什么都不返回。我检查了html 4的规格,说名称属性的值只以字母开头,但1不是一个字母,它怎么得到它返回而1.1不呢?还是在这里发生了一些其他的魔法?我使用最新版本的Chrome。感谢。

解决方案

通过HTML规则, name 属性可以有任何值:用CDATA类型声明。不要混淆与声明为具有NAME类型的属性的引用。请参阅 http://www.w3.org/TR/ html4 / interact / forms.html#adef-name-INPUT



在使用 $ POST [...] 在PHP中,您需要注意以下PHP规则:变量名称中的点和空格转换为下划线。例如< input name =ab/> 变为 $ _ REQUEST [a_b] http://www.php.net/manual/en/language.variables .external.php


$ b 因此 $ _ POST ['1'] 应该按原样运行工作,而不是 $ _ POST ['1.1'] 你需要写 $ _ POST ['1_1']

I use PHP to get radio button values from a html page. My html looks like this:

<input type="radio" name="1.1" value="yes">
<input type="radio" name="1.1" value="no">

<input type="radio" name="1" value="yes">
<input type="radio" name="1" value="no">

The result is that $_POST['1'] returns value, but $_POST['1.1'] returns nothing. I checked the html 4 specs, say value for name attribute only starts with letter, but 1 is not a letter, how come it gets returned while 1.1 does not? Or is there some other magic happening here? I use latest version of Chrome. Thanks.

解决方案

By HTML rules, the name attribute may have any value: it is declared with CDATA type. Do not confuse the with the references to attributes declared as having NAME type. See http://www.w3.org/TR/html4/interact/forms.html#adef-name-INPUT

In the use of $POST[...] in PHP, you need to note this PHP rule: "Dots and spaces in variable names are converted to underscores. For example <input name="a.b" /> becomes $_REQUEST["a_b"]." See http://www.php.net/manual/en/language.variables.external.php

So $_POST['1'] should work as is and does work, but instead of $_POST['1.1'] you need to write $_POST['1_1'].

这篇关于html中name属性的有效值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆