如何在jQuery中隐藏子元素子元素

时间:2017-11-16 10:29:09

标签: javascript jquery html

我有一个从MySQL表和PHP填充到一些嵌套子级别的菜单。 我的菜单是这样的:

一个

ç

如果第一次单击A显示所有子元素,我再单击A的子元素,显示子元素也很好。
但问题是,当我打开A的所有级别项目后点击B,它显示B子元素很好。但是,如果我单击A它再次显示除子子元素之外的所有元素。

我为此使用了jQuery。

所以我想恢复原状? (仅扩展顶级子元素,而不是子子元素),
怎么做?

data = '''actions/steps to (re-) produce the problem:
1) Media--> Music collectio--> on right side--> click on Add Favourite icon--> on clicking Add from Favourite icon--> (Delete from favourite ) will display--> again click on Delete the favourite

expected result/behaviour:
it should display the track as well

observed result/behavior:
1st track list will display then
2nd list of songs will display
3rd no records will display
this behaviour will appear again and again

possible impact: 
this can be an issue while driving

actions/steps to recover from error:
software version tested (including supplied software or CAF version if relevant):

MGU :- 17w.25.4-2'''

observed=[]

for i in data["Error Description"]:    
    if len(re.findall(r'(Observed result\/behavior:|observed result\/behavior:)([^(]*)Possible impact:', i))==1:    
        observed.append((re.findall(r'(Observed result\/behavior:|observed result\/behavior:)([^(]*)Possible impact:', i))[0][1])    
    else:    
        observed.append(" ".join((re.findall(r'(Observed result\/behavior:|observed result\/behavior:)([^(]*)Possible impact:', i))))
//this is my jquery code for elements clickable in menu.
$(document).ready(function() {
  $(".lichild").parent().hide();

  $(".limain").click(function() {
    $(this).children('ul').show();
    $(this).siblings(".limain").children('ul').hide();
  });
  $(".lichild").click(function() {
    $(this).children('ul').show();
    $(this).siblings().children('ul').hide()
  });
});

2 个答案:

答案 0 :(得分:1)

package Scrape;

   import java.io.File;

   public class Datascrape {

    public static void main(String[] args) throws InterruptedException, 
    IOException {

    WebDriver driver = new FirefoxDriver();

    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    driver.get(page url);

    // list of all links on first page  

    List<WebElement> lista1 = driver.findElements(By.cssSelector(""));

    // looping through those links            
       for (int j=0;j<=lista1.size(); j++){

    // click on link and open it in new window             
        WebElement link = lista1.get(j); 
        Actions newwin = new Actions(driver);
     newwin.keyDown(Keys.SHIFT).click(link).keyUp(Keys.SHIFT).build().perform();

     //  switch focus of WebDriver to the next found window handle (newly opened 
         window)

         String parentHandle = driver.getWindowHandle();
         for (String winHandle : driver.getWindowHandles()) {
         driver.switchTo().window(winHandle); 
         }

     //  do something here

    // close newly opened window when done with it and switch back to the 
    //   original window
            driver.close(); 
            driver.switchTo().window(parentHandle);

            }

   // TRY CLICK ON BUTTON AND MOVE TO ANOTER PAGE BUT IT's ALREADY TOO 
   //   LATE PROGRAM STOPS AND ERROR MESSAGE APPEARS ???

              driver.findElement(By.xpath("")).click();

             }
             }

答案 1 :(得分:1)

在兄弟姐妹中使用find并隐藏它。

app:layout_constraintEnd_toEndOf="@+id/YouVoted"
$(".lichild").parent().hide();

$(".limain").click(function() {
  $(this).children('ul').show();
  $(this).siblings(".limain").find('ul').hide(); // Change in this line
});
$(".lichild").click(function() {
  $(this).children('ul').show();
  $(this).siblings().children('ul').hide()
});