您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

HTML元素数组,名称=“ something []”或名称=“ something”?

HTML元素数组,名称=“ something []”或名称=“ something”?

PHP使用方括号语法将表单输入转换为数组,因此使用name="education[]"时将获得一个数组:

$educationValues = $_POST['education']; // Returns an array
print_r($educationValues); // Shows you all the values in the array

因此,例如:

<p><label>Please enter your most recent education<br>
    <input type="text" name="education[]">
</p>
<p><label>Please enter any prevIoUs education<br>
    <input type="text" name="education[]">
</p>
<p><label>Please enter any prevIoUs education<br>
    <input type="text" name="education[]">
</p>

将为您提供$_POST['education']数组内所有输入的值。

在JavaScript中,通过id获取元素更有效。

document.getElementById("education1");

ID不必与名称匹配:

<p><label>Please enter your most recent education<br>
   <input type="text" name="education[]" id="education1">
</p>
其他 2022/1/1 18:19:14 有508人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶