How to edit specific sections of a php code using javascript

如何编辑的特定部分,PHP代码使用JavaScript

Tags: javascript
标签: javascript

问题 (Question)

Hello guys I was wondering if I could remove 2 specific sections of this code using JavaScript...

Original Code:

<div class="chat-column">
    <div class="chat-column-head chat-container"></div>
    <div class="chat-wrapper chat-column-body chat-container"></div>
    <div class="chat-column-head mediapost-container"></div>
    <div class="chat-wrapper chat-column-body mediapost-container"></div>
    <!--

     Ad section 

    -->
    <!--

     End Ad section 

    -->
    <div class="chat-column-head"></div>
    <div>
        <ul class="mediapost-list clearfix"></ul>
    </div>
    <div class="chat-column-head"></div>
    <div class="related-posts chat-column-body">
        <ul class="mediapost-list clearfix"></ul>
    </div>
    <div class="chat-column-head"></div>
    <div class="related-videos chat-column-body"></div>

I'd like to remove this section

<div class="chat-column-head"></div>
<div class="related-posts chat-column-body">
    <ul class="mediapost-list clearfix"></ul>
</div>

and

<div class="chat-column-head"></div>
<div>
    <ul class="mediapost-list clearfix"></ul>
</div>

Would it be easier to get rid of the ul listing and keep the titles even though it would be horrible to keep?

大家好,我在想我是否能去除2的特定部分,该代码使用JavaScript…

原代码:

<div class="chat-column">
    <div class="chat-column-head chat-container"></div>
    <div class="chat-wrapper chat-column-body chat-container"></div>
    <div class="chat-column-head mediapost-container"></div>
    <div class="chat-wrapper chat-column-body mediapost-container"></div>
    <!--

     Ad section 

    -->
    <!--

     End Ad section 

    -->
    <div class="chat-column-head"></div>
    <div>
        <ul class="mediapost-list clearfix"></ul>
    </div>
    <div class="chat-column-head"></div>
    <div class="related-posts chat-column-body">
        <ul class="mediapost-list clearfix"></ul>
    </div>
    <div class="chat-column-head"></div>
    <div class="related-videos chat-column-body"></div>

我想把这段

<div class="chat-column-head"></div>
<div class="related-posts chat-column-body">
    <ul class="mediapost-list clearfix"></ul>
</div>

<div class="chat-column-head"></div>
<div>
    <ul class="mediapost-list clearfix"></ul>
</div>

它会更容易摆脱的ul上市和保持冠军尽管很可怕呢?

最佳答案 (Best Answer)

First, Your code has nothing to do with PHP.

Second,

var names = ["chat-column-head",
             "related-posts chat-column-body",
             "chat-column-head"]

var cch = document.getElementByClassName("chat-column-head")[0]
cch.parentNode.removeChild(cch.nextSibling)
for(var i=0; i<names.length; i++) {
  var element = document.getElementByClassName(names[i])[0]
  element.parentNode.removeChild(element)
}

第一,你有没有PHP代码。

第二,

var names = ["chat-column-head",
             "related-posts chat-column-body",
             "chat-column-head"]

var cch = document.getElementByClassName("chat-column-head")[0]
cch.parentNode.removeChild(cch.nextSibling)
for(var i=0; i<names.length; i++) {
  var element = document.getElementByClassName(names[i])[0]
  element.parentNode.removeChild(element)
}

答案 (Answer) 2

You cannot edit php code with javascript, PHP runs before the page gets to the browser. However the code you posted is HTML and yes you can remove it with Javascript. You would need to assign an event with the task, probably either on page load or a button, and then write a function which removes that element.

你不能用JavaScript编辑的PHP代码,在PHP页面被浏览器运行。然而你上传的代码是HTML和JavaScript是你可以删除它。你将需要与任务分配一个事件,可能会在页面加载或一个按钮,然后写一个函数移除元素。

本文翻译自StackoverFlow,英语好的童鞋可直接参考原文:http://stackoverflow.com/questions/22080858