duanchu3376 2018-03-29 07:44
浏览 24
已采纳

在PHP中包含模板时删除旧内容

<?php include "main.php" #this file is supposed to be included after an event occurred ?>

 <!-- this should be deleted after include, also styles scripts and everything in this old-content id-->
         <div id="old-content">
         <link rel="stylesheet" href="custom.css">
    some content
        </div>

What i tried, i add the below in the old-content div, but jquery is included only in the template main.php

$("#old-content").empty();

Problem with this, is that files are not actually removed and when i view page source i can see the old content at the end

  • 写回答

4条回答 默认 最新

  • douxie7339 2018-03-29 07:48
    关注

    You can use .remove() method it takes elements out of the DOM. Use it when you want to remove the element itself, as well as everything inside it.

    $("#old-content").remove();
    

    // find elements
    var button = $("button")
    
    // handle click and add class
    button.on("click", function(){
      $("#banner-message").remove();
    })
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div id="banner-message">
      <p>Hello World</p>
      <button>Remove</button>
    </div>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 openwrt双栈NAT
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?
  • ¥15 (SQL语句|查询结果翻了4倍)
  • ¥15 Odoo17操作下面代码的模块时出现没有'读取'来访问
  • ¥50 .net core 并发调用接口问题
  • ¥15 网上各种方法试过了,pip还是无法使用