如何从 <li> 标签中删除此部分
How to remove this section from being enclosed in <li> tags
我找不到此页面 (http://www.drink-driving-lawyers.com.au/pleading-guilty-or-not-guilty) 的 "actual" 后端,我可以在其中删除使第一段带有项目符号的 <li>
和 <ul>
标记.
The decision to plead guilty or not guilty is the most important decision that you make in a drink driving case. It is very important if defending a drink driving charge to have all the information from your lawyer. Further down the page there are a number of defences to drink driving charges.
我们将 Wordpress 用作 CMS,每当我通过 WP Admin 转到该页面的后端时,该部分没有项目符号,也没有包含在 <ul>
和 <li>
代码中。然而,当您检查来源时,它显示为:
<ul class="postul">
<li class="first-child last-child">
<p>The decision to plead guilty or not guilty is the most important decision that you make in a drink driving case. It is very important if defending a drink driving charge to have all the information from your lawyer. Further down the page there are a number of defences to drink driving charges.</p>
<p>You have to weigh up the chance of winning a defence of your drink driving charges with the extra cost and the possibly worse penalty you may receive.</p>
我需要调整什么文件才能删除这些 <ul>
和 <li>
标签?
客户端
您可以轻松地将此位包含在您的 Appearance > Editor > footer.php
(或 header.php)中,并通过删除 <li class="first-child last-child">
:
来解决问题
<script type="text/javascript">
$(document).ready(function(){
var myList = $(".postul > li > *").first(); //find the first element after li
$(myList).unwrap(); //remove what's containing it without removing itself
});
</script>
看了评论,一定很容易理解我想做什么。但是让我们逐行分析:
$(document).ready(function()
等待 DOM 为 ready。
var myList = $(".postul > li > *").first();
我想要一个名为 myList
的变量。此变量表示(从 * 开始读取)= li
下的任何内容,其中 li
在另一个具有 [=64= 的元素中] 称为 postul
。
星号 = 任何元素(<div>
、<p>
或其他任何元素!)
此外,first()
如其所说,returns 只有 first 符合该条件的结果(因此页面中的其他项目不受影响)。
换句话说,找到这个:
<element class="postul">
<li>
<something> <!-- I WANT THIS! -->
<something> <!-- and NOT this -->
</li>
</element>
<element class="postul">
<li>
<something> <!-- NOT this either -->
</li>
</element>
最后:
$(myList).unwrap();
现在找到我的元素后,unwrap()它。这意味着:
Remove the parents of the set of matched elements from the DOM,
leaving the matched elements in their place.
这将导致我们的示例代码为:
<element class="postul">
<something> <!-- its parent is removed but it's still here -->
<something> <!-- this is NOT affected -->
</element>
<element class="postul">
<li>
<something> <!-- NEITHER this is affected -->
</li>
</element>
这应该会导致您想要实现的目标。
服务器端
很难说它到底来自哪里(虽然无法访问您的后端),但它肯定会影响您拥有的每个 post,因此它来自您的服务器端。这仅取决于您的模板以及 post 的结构,但您可以查看模板中的 single.php
或任何其他 post 相关 PHP 页面。
我找不到此页面 (http://www.drink-driving-lawyers.com.au/pleading-guilty-or-not-guilty) 的 "actual" 后端,我可以在其中删除使第一段带有项目符号的 <li>
和 <ul>
标记.
The decision to plead guilty or not guilty is the most important decision that you make in a drink driving case. It is very important if defending a drink driving charge to have all the information from your lawyer. Further down the page there are a number of defences to drink driving charges.
我们将 Wordpress 用作 CMS,每当我通过 WP Admin 转到该页面的后端时,该部分没有项目符号,也没有包含在 <ul>
和 <li>
代码中。然而,当您检查来源时,它显示为:
<ul class="postul">
<li class="first-child last-child">
<p>The decision to plead guilty or not guilty is the most important decision that you make in a drink driving case. It is very important if defending a drink driving charge to have all the information from your lawyer. Further down the page there are a number of defences to drink driving charges.</p>
<p>You have to weigh up the chance of winning a defence of your drink driving charges with the extra cost and the possibly worse penalty you may receive.</p>
我需要调整什么文件才能删除这些 <ul>
和 <li>
标签?
客户端
您可以轻松地将此位包含在您的 Appearance > Editor > footer.php
(或 header.php)中,并通过删除 <li class="first-child last-child">
:
<script type="text/javascript">
$(document).ready(function(){
var myList = $(".postul > li > *").first(); //find the first element after li
$(myList).unwrap(); //remove what's containing it without removing itself
});
</script>
看了评论,一定很容易理解我想做什么。但是让我们逐行分析:
$(document).ready(function()
等待 DOM 为 ready。
var myList = $(".postul > li > *").first();
我想要一个名为 myList
的变量。此变量表示(从 * 开始读取)= li
下的任何内容,其中 li
在另一个具有 [=64= 的元素中] 称为 postul
。
星号 = 任何元素(<div>
、<p>
或其他任何元素!)
此外,first()
如其所说,returns 只有 first 符合该条件的结果(因此页面中的其他项目不受影响)。
换句话说,找到这个:
<element class="postul">
<li>
<something> <!-- I WANT THIS! -->
<something> <!-- and NOT this -->
</li>
</element>
<element class="postul">
<li>
<something> <!-- NOT this either -->
</li>
</element>
最后:
$(myList).unwrap();
现在找到我的元素后,unwrap()它。这意味着:
Remove the parents of the set of matched elements from the DOM, leaving the matched elements in their place.
这将导致我们的示例代码为:
<element class="postul">
<something> <!-- its parent is removed but it's still here -->
<something> <!-- this is NOT affected -->
</element>
<element class="postul">
<li>
<something> <!-- NEITHER this is affected -->
</li>
</element>
这应该会导致您想要实现的目标。
服务器端
很难说它到底来自哪里(虽然无法访问您的后端),但它肯定会影响您拥有的每个 post,因此它来自您的服务器端。这仅取决于您的模板以及 post 的结构,但您可以查看模板中的 single.php
或任何其他 post 相关 PHP 页面。