是否有可能在HTML中有双重嵌套的输入标签数组? [英] is it possible to have double nested input tag arrays in html?

查看:105
本文介绍了是否有可能在HTML中有双重嵌套的输入标签数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果可能在html中有一个双重嵌套的输入数组,我试图重构我的页面之前想知道。我在表单中有一个8X5的元素组,这对我来说能够使用数组数组来解析它是很好的...像

  

等等

解决方案

您需要为每个字段的第一部分提供索引,否则就没有可以嵌套的东西,如果它能够工作,它看起来不像另一端的网格: / p>

第1行:

  name =list [0] [] 

第2行:

  name =list [1] []

p>

最后,当PHP和Rails开箱即用时,您的服务器需要支持这一点。我不确定其他服务器技术。例如,下面的HTML发布到PHP时:

 < form action =post.phpmethod =POST accept-charset =utf-8> 
< input type =textname =list [0] []value =1/>
< input type =textname =list [0] []value =2/>
< input type =textname =list [0] []value =3/>

< input type =textname =list [1] []value =4/>
< input type =textname =list [1] []value =5/>
< input type =textname =list [1] []value =6/>

< input type =textname =list [3] []value =7/>
< input type =textname =list [3] []value =8/>
< input type =textname =list [3] []value =9/>

< input type =submitname =Sendvalue =Sendid =Send/>
< / form>

如果在PHP中存在以下代码:

 <?php print_r($ _ POST ['list']); ?> 

输出结果为:

 数组

[0] =>数组

[0] => 1
[1] => 2
[2] => 3


[1] =>数组

[0] => 4
$ b [1] => 5
[2] => 6


[3] =>数组

[ 0] => 7
[1] => 8
[2] => 9




I'm wondering before I attempt to refactor my page if its possible to have a double nested input array in html. I have an 8X5 group of elements in a form and it would be nice for me to be able to parse it using an array of arrays...something like

    <input type="text" name="list[][]" /><input type="checkbox" name="list[][]" /> 

and so on

解决方案

You are going to need to supply indexes into the first part of each field or else there is nothing to nest, and if it did work, it wouldn't look like a grid on the other end:

Row 1:

 name="list[0][]"

Row 2:

 name="list[1][]" 

etc.

Finally, your server needs to support this as PHP and Rails do out of the box. I am not sure about other server technologies. For an example, the following HTML when posted to PHP:

<form action="post.php" method="POST" accept-charset="utf-8">
  <input type="text" name="list[0][]" value="1" />
  <input type="text" name="list[0][]" value="2" />
  <input type="text" name="list[0][]" value="3" />

  <input type="text" name="list[1][]" value="4" />
  <input type="text" name="list[1][]" value="5" />
  <input type="text" name="list[1][]" value="6" />

  <input type="text" name="list[3][]" value="7" />
  <input type="text" name="list[3][]" value="8" />
  <input type="text" name="list[3][]" value="9" />

  <input type="submit" name="Send" value="Send" id="Send" />
</form>

If in the PHP the following code exists:

<?php print_r($_POST['list']); ?>

The output is:

Array
(
    [0] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )

    [1] => Array
        (
            [0] => 4
            [1] => 5
            [2] => 6
        )

    [3] => Array
        (
            [0] => 7
            [1] => 8
            [2] => 9
        )

)

这篇关于是否有可能在HTML中有双重嵌套的输入标签数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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