gpt4 book ai didi

javascript - 当我提交表单时,仅从多输入名称给出一个值

转载 作者:行者123 更新时间:2023-12-03 05:24:46 26 4
gpt4 key购买 nike

这是我的代码示例:

<div class="panel panel-default"> <!--Day Plan-->

<div class="panel-heading">
<h4 class="panel-title"> <a class=" accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseFour"> ITINERARY </a> </h4>
</div>
<div id="collapseFour" class="panel-collapse collapse ">
<div class="panel-body dayplan"> <!--Day Plan-->

<div class="control-group" id="fields">
<label class="control-label" for="field1">Please add Day Plan </label>
<div class="controls_day_plan">
<div class="entry_day_plan input-group col-sm-12 col-xs-12 ">
<div class="form-group col-sm-2 col-xs-12">
<label for="exampleInputnumber"> Select Day </label>
<select class="form_line_only form-control" name="dp_day[]" id="select_time">
<option > 1 </option>
<option > 2 </option>
<option > 3 </option>
<option > 4 </option>
<option > 5 </option>
<option > 6 </option>
<option > 7 </option>
</select>
</div>
<div class="form-group col-sm-2 col-xs-12">
<label for="exampleInputnumber"> Select Time </label>
<select class="form_line_only form-control" name="dp_time[]" id="select_time">
<option selected> Full Day </option>
<option > Morning </option>
<option > After Noon </option>
<option > Evening </option>
<option > Night </option>
</select>
</div>
<div class="form-group col-sm-7 col-xs-12">
<label for="exampleInputnumber"> Please Select Place </label>
<!--<input type="text" name="dp_place[]" class="form-control form_line_only" id="select_place" placeholder="Please Select Place">-->
<input type="text" class="className form-control form_line_only" name="ex_name[]" id="ex_name" placeholder="Enter Add Excursion">
</div>
<span class="input-group-btn day_plan pull-left">
<button class="btn btn-success btn-add add_col" type="button"> <span class="glyphicon glyphicon-plus"></span> </button>
</span> </div>

<br>
<small>Press <span class="glyphicon glyphicon-plus gs"></span> to add another Day Plan)</small> </div>
</div>
</div>
<!--/.Day Plan-->

</div>
</div>

JavaScript:

$(function()

{

$("body").on('click', '.btn-add', function(e)

{

e.preventDefault();



var controlForm = $('.controls_day_plan:first'),

currentEntry = $(this).parents('.entry_day_plan:first'),

newEntry = $(currentEntry.clone()).appendTo(controlForm);



newEntry.find('input').val('');

controlForm.find('.entry_day_plan:not(:last) .btn-add')

.removeClass('btn-add').addClass('btn-remove')

.removeClass('btn-success').addClass('btn-danger')

.html('<span class="glyphicon glyphicon-minus"></span>');

}).on('click', '.btn-remove', function(e)

{

$(this).parents('.entry_day_plan:first').remove();



e.preventDefault();

return false;

});

});

每当我提交此表单时,它只会给我第一个输入值。

PHP 代码

$my = $_REQUEST['dp_day'];
print_r($my);

但输出只是第一个输入值。我做错了什么?

因为加载时输入字段值获取但克隆字段值无法获取。

最佳答案

您仅从表单中获取一个值的原因是您仅从表单中请求一个值。

$my = $_REQUEST['dp_day'];

在这里,您从表单请求单个对象。基本上,您在表单中询问的只是dp_day 的值,但仅此而已。如果您想从表单中获取更多变量,则必须请求提出另一个请求。

例如,如果您想要dp_time,则必须像这样发出另一个请求:

$time = $_REQUEST['dp_time'];

关于javascript - 当我提交表单时,仅从多输入名称给出一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41200252/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com