Div文本替换在其他div中

时间:2017-05-02 11:00:37

标签: php jquery wordpress

我想要class =" hotelname"在课堂上回复文字=" a"和class =" hotelname"是隐藏。那可能吗?我使用jQuery代码,但它无法正常工作。

<form id="" class="" method="GET" action="http://localhost/blue_bucket/county/" enctype="multipart/form-data">
        <h2 class="a"></h2>
    <?php
    foreach ($query as $row) 
    {   
        ?>
        <h3 class="hotelname"><?php echo $hotelnames =  $row->hotel; ?></h3>

        <div class="book-it-btn">
            <button type="submit" name="submit" class="btn btn-default">Apply</button>
        </div>
    </form>
        <?php
    }
    ?>  

Jquery的:

jQuery(".a").append(jQuery(".hotelname").html());

1 个答案:

答案 0 :(得分:0)

根据我的理解,您希望将.hotelname类值放入.a类,然后您想要隐藏.hotelname类元素?

检查下面的工作代码段

 var hotelName = $(".hotelname").text();

      $(".a").text(hotelName);

&#13;
&#13;
$(document).ready(function() {
  var hotelName = $(".hotelname").text();
  
  $(".a").text(hotelName)
  $(".hotelname").hide();

})
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<form id="" class="" method="GET" action="http://localhost/blue_bucket/county/" enctype="multipart/form-data">
  <h2 class="a"></h2>
  <?php
    foreach ($query as $row) 
    {   
        ?>
    <h3 class="hotelname">My hotel</h3>

    <div class="book-it-btn">
      <button type="submit" name="submit" class="btn btn-default">Apply</button>
    </div>
</form>
<?php
    }
    ?>
&#13;
&#13;
&#13;