追加不插入值

时间:2019-04-26 06:53:43

标签: php jquery file append

这里我的问题是通过添加选择的值没有插入到发布值中。在这里粘贴我的代码

      <div id="update_new_<?php echo $value->id;?>" class="update_new_<?php echo $value->id;?>">
            <div class="form-group mb0" style="margin-bottom: 0px">
                <label for="field-1"
                       class="col-sm-4 control-label">Other Document</label>
                <div class="col-sm-5">
                    <div class="fileinput fileinput-new" data-provides="fileinput">
                        <?php
                        if (!empty($value->documents)) {
                            $uploaded_file = json_decode($value->documents);
                        }
                        if (!empty($uploaded_file)):foreach ($uploaded_file as $v_files_image): ?>
                            <div class="">
                                <input type="hidden" name="fileName[]"
                                       value="<?php echo $v_files_image ?>">

                                <span class=" btn btn-default btn-file">
                                <span class="fileinput-filename"> <?php echo $v_files_image ?></span>
                                <a href="javascript:void(0);" class="remCFile" style="float: none;">×</a>
                                </span>
                                <strong>
                                    <a href="javascript:void(0);" class="RCF"><i
                                            class="fa fa-times"></i>&nbsp;Remove</a></strong>
                                <p></p>
                            </div>

                        <?php endforeach; ?>
                        <?php else: ?>
                            <span class="btn btn-default btn-file"><span
                                    class="fileinput-new">Select File</span>
                                                        <span class="fileinput-exists"><?= lang('change') ?></span>
                                                        <input type="file" name="files[]">
                                                    </span>
                            <span class="fileinput-filename"></span>
                            <a href="#" class="close fileinput-exists" data-dismiss="fileinput"
                               style="float: none;">&times;</a>
                        <?php endif; ?>
                    </div>
                    <div id="msg_pdf" style="color: #e11221"></div>
                </div>
                <div class="col-sm-3">
                    <strong><a href="javascript:void(0);" id="update_more" onclick="add_field('<?php echo $value->id;?>');" u_id="<?php echo $value->id;?>" class="addCF update_more_<?php echo $value->id;?>"><i
                                class="fa fa-plus"></i>&nbsp;Add More
                        </a></strong>
                </div>
            </div>



        </div>

这是我的脚本,请看

<script type="text/javascript">

 var maxAppends = 0;
 function add_field(id)
 {

      var update_new = $('<div class="form-group" style="margin-bottom: 0px">\n\
             <label for="field-1" class="col-sm-4 control-label">Documentsss</label>\n\
 <div class="col-sm-5">\n\
 <div class="fileinput fileinput-new" data-provides="fileinput">\n\
       <span class="btn btn-default btn-file"><span class="fileinput-new">Select file</span><span class="fileinput-exists" >Change</span><input type="file" name="files[]" ></span> <span class="fileinput-filename"></span><a href="#" class="close fileinput-exists" data-dismiss="fileinput" style="float: none;">&times;</a></div></div>\n\<div class="col-sm-2">\n\<strong>\n\<a href="javascript:void(0);" class="remCF"><i class="fa fa-times"></i>&nbsp;Remove</a></strong></div>');
     maxAppends++;

     $(".update_new_"+id).append(update_new);


   }
   </script>

在此处单击以添加更多字段时,它正确地出现了,但是在通过邮递传递值时,在该字段中选择的值没有获得,我怀疑这是否是由于使用动态方式添加数据而引起的。 我发现的问题是问题<div id="update_new_<?php echo $value->id;?>">在foreach循环中,所以我们如何在foreach循环中做到这一点。

1 个答案:

答案 0 :(得分:0)

在您的脚本中,将.update_new_更改为#update_new_