Jquery为empty()但在清空时不要清空前两个对象

时间:2017-05-23 11:58:11

标签: jquery

这就是我的div结构的样子:

<div id="firstDiv">
   <div class="itemName"></div>
   <div class="exitContainer"></div>
   <div id="secondDiv">
       <div class="itemName"></div>
       <div class="exitContainer"></div>   
  </div>
   <div id="thirdDiv">
       <div class="itemName"></div>
       <div class="exitContainer"></div>   
  </div>
</div>

我想删除除以下内容之外的所有内容:

<div id="firstDiv">
   <div class="itemName"></div>
   <div class="exitContainer"></div>

是空的()是最好的方法还是有办法实现这个目标?

提前致谢

1 个答案:

答案 0 :(得分:0)

 <build>
    <resources>
        <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>META-INF/persistence.xml</include>
                </includes>
         </resource>
     </resources>
</build>
    $string = '

@if(topLevel)
{{
  <form method="post">
    @if(mediumLevel)
    {{
      <input>
    }}
  </form>
  <form method="post">
    @if(bottomLevel)
    {{
      <input>
    }}
  </form>
}}';
function string_between($string, $start, $end){
    $total = substr_count($string, $start);
    for ($i = 0; $i < $total; $i++){
        $string = ' ' . $string;
        $ini = strpos($string, $start);
        $ini += strlen($start);
        $len = strpos($string, $end, $ini) - $ini;
        $result[$i] = substr($string, $ini, $len);
        $string = substr($string, $len);
        $ini = strpos($string, $start);
        $string = substr($string, $ini);
    }
    return $result;
}

function string_between_brackets($string, $start, $end){
    $total = substr_count($string, $start);
    for ($i = 0; $i < $total; $i++){
        $string = ' ' . $string;
        $ini = strpos($string, $start);
        $ini += strlen($start);
        if ($i == 0){
            $len = strrpos($string, $end, $ini) - $ini;
        } else {
            $len = strpos($string, $end, $ini) - $ini;
        }
        $result[$i] = substr($string, $ini, $len);
        $string = substr($string, $ini);
    }
    return $result;
}

$parsed = string_between($string, '@if(', ')');
$parsedContent = string_between_brackets($string, '{{', '}}');
$i = 0;
$parsedString = array_combine($parsed, $parsedContent);
var_dump($parsedString);

/*array (size=3)
  'topLevel' => string '
  <form method="post">
    @if(mediumLevel)
    {{
      <input>
    }}
  </form>
  <form method="post">
    @if(bottomLevel)
    {{
      <input>
    }}
  </form>
' (length=165)
  'mediumLevel' => string '
      <input>
    ' (length=19)
  'bottomLevel' => string '
      <input>
    ' (length=19)*/

除了您添加到“:not()”

之外,这将删除所有内容