如何将输入框的数组名称添加到HTML?

时间:2015-12-19 16:34:03

标签: javascript php html mysql

我在使用点击功能向HTML添加输入框数组时遇到问题。

这里是JavaScript:

var i = $('table tr').length;
var count = $('table tr').length;
var row = i;
var a = 0;

$(function(){

  $(".addmore").on('click', function (a) {
    var cell= $(this).parents('td');
    var currentValue = cell.prev().find("[name=jumpack]").data('addmore');
    if(currentValue==null || currentValue == undefined)
    {
      currentValue =0;  
    }
    else
    {
      currentValue=parseInt(currentValue);
    }
    console.log(currentValue)
    var data = "<td><input class='form-control sedang' type='text' id='packinglist_" + $(this).index() + "' name='packinglist[]'/></td>";
    cell.parents('tr').find('table tr').append(data);
    currentValue++;
    cell.prev().find("[name=jumpack]").val(currentValue).data('addmore',currentValue)
  });
});

这是我的HTML:

<div class='table-responsive'>
    <table class='table table-bordered'>
    <tr>
    <th>No</th>
    <th>Jenis Benang</th>
    <th>Warna</th>
    <th>Lot</th>
    <th>Netto</th>
    <th>Box</th>
    <th>Cones</th>
    <th>Keterangan</th>
    <th></th>
    </tr>";

$s=mysql_query("SELECT * FROM surat_jalan order by identitas_packing_surat DESC");
$a=mysql_fetch_array($s);

for($i=1;$i<=$_POST['jumlahdata'];$i++)
{
    $nomor = $a[19];
    $iden = $nomor + $i;
        echo"   <tr>
        <td><span id='snum'>$i.</span></td>
        <input class='form-control' type='hidden' id='hiddenlot_$i' name='hiddenlot[]' />
        <input class='form-control' type='hidden' id='hiddencustomer_$i' name='hiddencustomer[]' />
        <input class='form-control' type='hidden' id='hiddenprice_$i' name='hiddenprice[]' />
        <td><input class='form-control' type='text' id='jenisbenang_$i' name='jenisbenang[]' readonly/></td>
        <td><input class='form-control' type='text' id='warna_$i' name='warna[]' readonly/></td>                                
        <td><input class='form-control' type='text' id='lot_$i' name='lot[]' required/></td>
        <td><input class='form-control sedang' type='text' id='netto_$i' name='netto[]' required/> </td>
        <td><input class='form-control pendek' type='text' id='box_$i' name='box[]'/> </td>
        <td><input class='form-control pendek' type='text' id='cones_$i' name='cones[]'/> </td>
        <td><input class='form-control' type='text' id='keterangan_$i' name='keterangan[]'/>
        <input class='form-control' type='text' id='keterangan_$i' name='identitas[]' value='$iden'/>
        <input class='form-control' type='text' id='jumrow_$i' name='jumpack[]' value=''/>  
        </td>
        <td><a><span class='glyphicon glyphicon-plus addmore' id='$i'></span></a> </td>
      <td colspan='10'>
            <table id='keatas_$i' class='keatas'>
                <tr></tr>
            </table>

    </td>
    </tr>
    ";
}

所以我的问题是我必须将jumpack[]插入到数据库中,但是name="jumpack[]"有很多值,它通过计算有多少个名为packinglist的文本框名称来获取它的值,所以我必须为jumpack[]创建一个数组,但是当我这样做时,JavaScript没有用,因为它有不同的名称,所以我的问题是如何将JavaScript上的[name=jumpack]更改为数组?

0 个答案:

没有答案