HTML Element Array,name =“something []”或name =“something”?我在这个网站上看到了一些东西: 在JavaScript和PHP中处理HTML表单元素的数组http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=343它说将数组放在name属性中以及如何获取输入集合的值。例如name="education[]"但据我所知,HTML输入元素是数组就绪的name。在客户端(GetElementsByName)或服务器端($_POST在PHP或Request.FormASP.NET中),例如:name="education",那么与...有什么不同[]?
3 回答
肥皂起泡泡
TA贡献1829条经验 获得超6个赞
如果您有复选框,则可以传递一组已检查的值。
<input type="checkbox" name="fruits[]" value="orange"/><input type="checkbox" name="fruits[]" value="apple"/><input type="checkbox" name="fruits[]" value="banana"/>
还有多个选择下拉列表
<select name="fruits[]" multiple> <option>apple</option> <option>orange</option> <option>pear</option></select>
偶然的你
TA贡献1841条经验 获得超3个赞
这不一样。如果您发布此表单:
<input type="text" name="education[]" value="1"><input type="text" name="education[]" value="2"><input type="text" name="education[]" value="3">
你会得到一个PHP数组,在这个例子中你会得到$_POST['education'] = [1, 2, 3]
。
如果你发布此表格没有 []
:
<input type="text" name="education" value="1"><input type="text" name="education" value="2"><input type="text" name="education" value="3">
你会得到最后一个值,在这里你会得到$_POST['education'] = 3
。
- 3 回答
- 0 关注
- 610 浏览
相关问题推荐
添加回答
举报
0/150
提交
取消