2015-02-05 47 views
-4

這個腳本在Chrome和Firefox中工作正常,但不是Safari ...簡單的Java腳本在Safari中不工作?

請幫忙嗎?

<ul class="SubMenu"> 
    <li>Shop By Category 
     <ul> 
      <li> 
      ----Some Text---- 
      </li> 
     </ul> 
    </li> 
</ul> 
$(document).ready(function() { 
    $("li").click(function() { 
     //Toggle the child but don't include them in the hide selector using .not() 
     $('li > ul').not($(this).children("ul").toggle()).hide(); 

    }); 
}); 
+0

你能提供一個工作jsfiddle嗎? – ummahusla 2015-02-05 16:44:47

+1

「不工作」如何?你期望會發生什麼,而發生什麼呢?你在控制檯中看到什麼?當你調試? – 2015-02-05 16:46:18

回答

0

爲了測試的緣故,我加入這一切都包含以下內容的HTML文件,一切似乎在所有瀏覽器做工精細。它是如何失敗的?

<html> 
<head> 
    <script src="https://code.jquery.com/jquery-2.1.3.min.js" charset="utf-8"></script> 
    <title></title> 
</head> 
<body> 
    <ul class="SubMenu"> 
     <li>Shop By Category 
     <ul> 
      <li> 
      ----Some Text---- 
      </li> 
     </ul> 
     </li> 
    </ul> 
<script type="text/javascript"> 
    $(document).ready(function() { 
     $("li").click(function() { 
     //Toggle the child but don't include them in the hide selector using .not() 
     $('li > ul').not($(this).children("ul").toggle()).hide(); 

     }); 
    }); 

</script> 

</body> 
</html> 
+0

非常感謝!我剛剛嘗試了你的腳本和它在safari上的工作,Il必須運行我的代碼並檢查錯誤,我只在這裏上傳了基本結構,也許是我的CSS。 – lugreen 2015-02-05 19:23:28

+0

我在運行這個腳本之前遇到了一個錯誤,讓Safari瀏覽器首先閱讀這個腳本,解決了這個問題。謝謝 – lugreen 2015-02-05 19:39:35