如何在JQUERY中附加这个div

时间:2018-03-26 18:46:22

标签: jquery html

如何在JQUERY中附加此div 我的JQUERY有些麻烦。

  • PHP -------------------------

        <?php include "Header.php";
        include "Connection.php";
        //List Medecin
    
        $stmt = $con->prepare("SELECT * FROM analyse");
        $stmt->execute();
        $rows = $stmt->fetchAll();
        $i=0;
    ?>
    

DIV -----------------

  <div id="contun">
    <div id="listA" class="form-group row">
    <label class="col-xl-12 col-md-3 form-control-label">
    Analyse N° <?php echo ++$i; ?>
    <span class="required">*</span>
    </label>
    <div class=" col-xl-12 col-md-9">
      <select style="width:534px; height:36px;" class="form-control" data-plugin="select2">
      <option> </option>
      <?php
      foreach($rows as $row){ 
      echo "<option value=".$row['Id_A'].">".$row['Type_A']."</option>";
      }
      ?>
      </select>
    </div>
  </div>

按钮-------------------------

<div id="ADD_div" class="form-group col-xl-12 text-left padding-top-m">
    <h1  class="btn btn-primary">+</h1>
</div>

SCRIPT --------------------------------------------

<script>
    $(document).ready(function(){
      $("#ADD_div").click(function (e){
        $('#contun').append($('#listA'));
      });
    });
</script>

2 个答案:

答案 0 :(得分:0)

如果我理解正确你只想在div的末尾添加更多文字? 在这种情况下,你可以这样做:

$(document).ready(function(){
  $("#ADD_div").click(function (e){
    $('#contun').html($('#contun').html() + "Your appended text or html");
  });
});

答案 1 :(得分:0)

append函数应将HTML作为参数,因此您必须使用div获取$('#listA').html() HTML。
检查更新的代码

$(document).ready(function() {
  $("#ADD_div").click(function(e) {
    $('#contun').append($('#listA').html());
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="contun">
  <div id="listA" class="form-group row">
    <label class="col-xl-12 col-md-3 form-control-label">
    <span class="required">*</span>
    </label>
    <div class=" col-xl-12 col-md-9">
      <select style="width:534px; height:36px;" class="form-control" data-plugin="select2">
      <option> </option>
      <option>AA</option>
      <option>BB</option>
      <option>CC</option>
      </select>
    </div>
  </div>
</div>
<div id="ADD_div" class="form-group col-xl-12 text-left padding-top-m">
  <h1 class="btn btn-primary">+</h1>
</div>