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

图片转代码服务由CSDN问答提供 功能建议

 &lt;?php include“main.php”#这个文件应该包含在一个事件之后 发生了吗?&gt; 
 
&lt;! - 这应该在包含之后删除,还要修改脚本以及此旧内容ID中的所有内容 - &gt; 
&lt; div id =“old-content”&gt; \  n&lt; link rel =“stylesheet”href =“custom.css”&gt; 
一些内容
&lt; / div&gt; 
   
 
 

我尝试过的, 我在旧内容div中添加以下内容,但jquery仅包含在模板 main.php

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

问题是,文件实际上没有被删除,当我查看页面源我可以看到 最后的旧内容

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

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条)

相关推荐 更多相似问题