因为之前不知道input里的名字可以有数组形式的,所以代码写成如下,就是每个新生成的名字后面加一个字符来区分其他的。 希望哪位朋友能帮帮我,我该怎么写下去? 如果用input名字是数组形式的,我该怎么改如下代码
我想要的就是生成很多这些表单内容之后,用post传过去的话,php页面该怎么接收这么多的内容,怎么区分不同的标题和内容信息。谢谢php代码<form name="userinfo" method="post" action="" enctype="multipart/form-data"  onsubmit="return false;" >
<input type="hidden" name="user_seq" value="{user.user_seq}" />
<input type="hidden" name="has_user_login_id" value="{user.has_user_login_id}" />
<span class="bigtitle"><input type = "text" name="big_title" value=""></span>
<div id="use_flag">
<input type="checkbox" name="use_flag" id="use_flag" value="">使用与否
</div>
<fieldset>
<legend>New info</legend>
<table class="formTable">
<tbody>
<tr>
<th><input type="checkbox" name="title_idx" value="">{=_('标题')}</th>
<td colspan="3" class="length"><input type="text" name="title" value="" ></td>
</tr>
<tr> 
<th>{=_('内容')}</th>
<td colspan="3">
<input type="radio" id="textbox" name="select" value="textbox"> Textbox
<input type="radio" id="radio"   name="select" value="radio"> radio button
<input type="radio" id="checkbox" name="select" value="checkbox"> checkbox
<br> 
</td>
</tr>
</tbody>
</table>
<br>
<div class="edit">
<button class="btn" id="add">继续</button>
<button class="btn" id="del">删除</button>
</div>
</fieldset>
</form>JS代码(function($){
$(document).ready(function(){

var flag  = $('#use_flag').is(':checked')?'T':'F';
var title = $('input[name=title]');

$('#textbox').click(function(){
$(this).parent().find('input[type="text"]').remove();
$(this).parent().find('button').remove();

});

var j=0;
$('#radio').click(function(){

$(this).parent().find('input[type="text"]').remove();
$(this).parent().find('button').remove();

var tr_last = $('.formTable tbody tr td').eq(1);
if(tr_last.find('.btn_radio_opt').length < 1)
{
tr_last.append('<span style="display:block;margin-top:5px"><input type="text" name="radio" value=""><button name="radio_btn_add" class="btn_radio_opt">추가</button></span>');

$('.btn_radio_opt').click(function(){
$(this).after('<div class="radioid"><span style="display:block;margin-top:5px"><input type="text" name="radio" value=""><button name="radio_btn_del" class="btn_radio_del_opt">삭제</button></span></div>');
/*********** text & button**************************************************************************************/
$('.formTable tbody tr').eq(1).find('input:text').each(function(){
var textname = $(this).attr("name").substr(0,5);
$(this).attr("name",textname+i+(j++));
});
$('.formTable tbody tr').eq(1).find('button').each(function(){
var btn = $(this).attr("name").substr(0,13);
$(this).attr("name",btn+i);
});
/****************************************************************************************************************/
$('.btn_radio_del_opt').click(function(){
$(this).prev().remove();
$(this).remove();
});
});
}
/*********** text & button**********************************************************************************************/
$('.formTable tbody tr').eq(1).find('input:text').each(function(){
var textname = $(this).attr("name").substr(0,5);
$(this).attr("name",textname+i);
});
$('.formTable tbody tr').eq(1).find('button').each(function(){
var btn = $(this).attr("name").substr(0,13);
$(this).attr("name",btn+i);
});
/***********************************************************************************************************************/
});
var z=0;
$('#checkbox').click(function(){

$(this).parent().find('input[type="text"]').remove();
$(this).parent().find('button').remove();

var tr_last = $('.formTable tbody tr td').eq(1);
if($(tr_last).find('.btn_checkbox_opt').length < 1)
{
$(tr_last).append('<span style="display:block;margin-top:5px"><input type="text" name="checkbox" value=""><button name="chk_btn_add" class="btn_checkbox_opt">추가</button></span>');
$('.btn_checkbox_opt').click(function(){
$(this).after('<span style="display:block;margin-top:5px"><input type="text" name="checkbox" value=""><button name="chk_btn_del" class="btn_chk_del_opt">삭제</button></span>');

/*********** text & button************************************************************************************/
$('.formTable tbody tr').eq(1).find('input:text').each(function(){
var textname = $(this).attr("name").substr(0,8);
$(this).attr("name",textname+i+(z++));
});
$('.formTable tbody tr').eq(1).find('button').each(function(){
var btn = $(this).attr("name").substr(0,11);
$(this).attr("name",btn+i);
});
/*************************************************************************************************************/
$('.btn_chk_del_opt').click(function(){
$(this).prev().remove();
$(this).remove();
});
});
}
/*********** text & button*******************************************************************************************/
$('.formTable tbody tr').eq(1).find('input:text').each(function(){
var textname = $(this).attr("name").substr(0,8);
$(this).attr("name",textname+i);
});
$('.formTable tbody tr').eq(1).find('button').each(function(){
var btn = $(this).attr("name").substr(0,11);
$(this).attr("name",btn+i);
});
/********************************************************************************************************************/
});
var i = 0;
$('#add').click(function(){
j=0;
z=0;
if($('.formTable tbody tr').eq(0).find('input[type=text]').val() == "")
{
alert('请输入标题!');return;
}
else
{
if($('.formTable tbody tr').eq(1).find('input[type=radio]:checked').length!= 0)
{
i++;
var tr_last = $('.formTable tbody tr:last');
$(tr_last).after($('.formTable tbody tr').eq(1).clone()).after($('.formTable tbody tr').eq(0).clone()); /************* title & radio***************************************************************************************/
$('.formTable tbody tr').eq(0).find('input:text').each(function(){
var title = $(this).attr("name").substr(0,5);
$(this).attr("name",title+i);
});
$('.formTable tbody tr').eq(1).find('input:radio').each(function(){
var oldname = $(this).attr("name").substr(0,6);
$(this).attr("name",oldname+i);
});
/*********** text & button &checkbox_index**************************************************************************************/
$('.formTable tbody tr').eq(1).find('input:text').each(function(){
var textname = $(this).attr("name").substr(0,5);
$(this).attr("name",textname+i);
});
$('.formTable tbody tr').eq(1).find('button').each(function(){
var btn = $(this).attr("name").substr(0,5);
$(this).attr("name",btn+i);
});
$('.formTable tbody tr').eq(0).find('input[type=checkbox]').each(function(){
    var chk    =    $(this).attr("name").substr(0,9);
    $(this).attr("name",chk+i);
})
/****************************************************************************************************************/
$('.formTable tbody tr').eq(0).find('input[type=checkbox]').attr("checked",false);
$('.formTable tbody tr').eq(0).find(':input[type=text]').val("");
$('.formTable tbody tr').eq(1).find(':input[type=text]').remove();
$('.formTable tbody tr').eq(1).find('.btn_radio_opt').remove();
$('.formTable tbody tr').eq(1).find('.btn_radio_del_opt').remove();
$('.formTable tbody tr').eq(1).find('.btn_chk_del_opt').remove();
$('.formTable tbody tr').eq(1).find('.btn_checkbox_opt').remove();
$('.formTable tbody tr').eq(1).find(':text[name="radio"]').remove();
$('.formTable tbody tr').eq(1).find(':text[name="checkbox"]').remove();
/***************************************************************************************************************/
}
else
{
alert('请输入内容格式');return;
}
}
});
$('#del').click(function(){
if($('.formTable tbody tr').find('input[type=checkbox]:checked').length < 1)
{
alert('请选择要删除的标题');return;
}
else
{
$('.formTable tbody tr').find('input[type=checkbox]:checked').parent().next().parent().next().remove();
$('.formTable tbody tr').find('input[type=checkbox]:checked').parent().next().remove();
$('.formTable tbody tr').find('input[type=checkbox]:checked').parent().remove();
}
});
$('#popup>thead>tr>td>span>a.save').click(function(){

var frm = $('form[name=userinfo]');
var url = '/hr/survey/insert';
if($(frm).find(':hidden[name=user_seq]').val() > 0)
{
url = '/hr/survey/update';
}
$(frm).attr('action', url);
$(frm).submit();
});
});
})(jQuery);

解决方案 »

  1.   

    数组方式传递过去你也得自己区分,数组方式只是写代码的时候方便些.
    <input type="text" name="name[]"> $_POST['name'][索引] 这个是接受的方法.你可以pinrt_r($_POST['name'])看看的.所以就照你现在的继续做吧...呵呵 
      

  2.   

    代码高手是不用框架的,新手最好采用比较成熟的框架。如thinkphp
      

  3.   

    普通的文本框啦,文本域啦,单选按钮什么的,表单提交接收的时候,就$_POST['name']  ok了,像复选框这类,一般才需要数组的形式获取,也无非就是<input name="name[]" type="checkbox">
    php中获取的时候 $_POST['name']这样就把你所选的复选框的值赋给这个数组
      

  4.   

    $items 的样子如下array(
     [0] => array(
       [0] => 'textboxccc'                 这里都是标题title
       [1] => 'radioaaa'
     )
     [1]=> array(
       [0] => 'textbox'                    这里都是类型type
       [1] => 'radio'
     )
    )现在想用foreach($items AS item)
           {
       变量title = '';
       变量type  = '';
           }给变量title和type赋值,但不知道怎么赋值才正确。他们是互相对应的