久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Safari 錯誤:當使用 JS 刪除項目時,first-child 不更

Safari bug :first-child doesn#39;t update display:block when items are removed with JS(Safari 錯誤:當使用 JS 刪除項目時,first-child 不更新 display:block)
本文介紹了Safari 錯誤:當使用 JS 刪除項目時,first-child 不更新 display:block的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

默認情況下隱藏所有項目的列表,第一個 li 具有 blockdisplay.問題是如果第一個元素被刪除,這將不會更新,實際上是創建一個應該顯示的新的第一個子元素.在 Safari 中,不顯示應該顯示的新 li.

With a list of items where all are hidden by default, the first li has a display of block. The problem is that this won't update if the first element is removed, de facto making a new first-child which should be displayed. In Safari the new li that should show is not displayed.

HTML

<ul class="list">
  <li class="item">1</li>
  <li class="item">2</li>
  <li class="item">3</li>
</ul>
<button>click me </button>

CSS

.list .item { display: none } 
.list .item:first-child { display:block}

JS

$('button').on('click', function(e) {
  $('ul li:first').remove().appendTo($('ul'));
});

查看小提琴:http://jsfiddle.net/BFTan/1/

在所有其他瀏覽器中單擊該按鈕將循環瀏覽項目,但在 Safari 中沒有任何更新.

In all other browsers clicking the button will cycle through the items but in Safari nothing updates.

推薦答案

這似乎是 display: none 和從文檔樹中刪除的對象的問題,當您使用 :first-child,而不是 Safari 處理 :first-child 選擇器本身的問題.

This appears to be a problem with display: none and objects removed from the document tree which manifests itself when you use :first-child, rather than a problem intrinsic to Safari's handling of the :first-child selector itself.

無論如何,這絕對是一個錯誤.即使您將對象(及其內容)與其父級分離,jQuery 也不會破壞該對象,但是當從其父級分離一個元素時,無論 n 的值如何,它都不應再是其父級的第 n 個子級,因此下一個元素成為第一個孩子的應該相應地匹配 :first-child.

Either way, this is definitely a bug. jQuery doesn't destroy the object even when you detach it (and its contents) from its parent, but when detaching an element from its parent it should no longer be the nth child of its parent for whatever value of n, so the next element that becomes the first child should match :first-child accordingly.

如果您將代碼中的 :first-child 更改為 :not(:last-child),例如 this,這樣您就有兩個元素同時顯示,當您單擊按鈕時,您會在 Safari 中注意到第一個元素消失,留下第二個元素完好無損(以及仍然隱藏的第三個).

If you change :first-child in your code to :not(:last-child), like this, such that you have two elements displaying at a time, you'll notice in Safari when you click the button the first element disappears, leaving the second element intact (as well as the third which is still hidden).

我還發現,如果您在列表本身上使用 :empty 選擇器添加新的空規則:

I also found that if you add a new empty rule with the :empty selector on the list itself:

/* Or even .list:empty even though it's not actually empty */
.list:not(:empty) {}

一切都會突然在 Safari 中正常工作.更奇怪的是,這種解決方法不適用于任何其他 3 級偽類.它僅適用于 :empty:not(:empty).

Everything will suddenly work correctly in Safari. Even more bizarre is that this workaround does not work with any other level 3 pseudo-class. It only works with :empty or :not(:empty).

這篇關于Safari 錯誤:當使用 JS 刪除項目時,first-child 不更新 display:block的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

CSS selector when :target empty(:target 為空時的 CSS 選擇器)
Does the CSS direct decendant (gt;) not have any value in selectivity?(CSS 直接后代 (gt;) 在選擇性方面沒有任何價值嗎?)
Using querySelectorAll(). Is the result returned by the method ordered?(使用 querySelectorAll().方法返回的結果是否有序?)
nth-Child CSS selectors(nth-子 CSS 選擇器)
Using same ID for multiple HTML tags?(對多個 HTML 標簽使用相同的 ID?)
TestCafe - How to check if a web element exists or does not exist without failing the test?(TestCafe - 如何在不通過測試的情況下檢查 Web 元素是否存在?)
主站蜘蛛池模板: 五月天视频 | 日韩综合在线 | 狠狠干 | 欧美日韩亚洲视频 | 久久日韩精品 | 久久xxxx | 久久久久久综合 | 99久久精品国产一区二区成人 | 免费黄视频网站 | 日韩视频在线播放 | 欧美一级黄色录像 | 欧美日韩亚洲一区二区三区 | 四虎最新地址 | 91在线观 | 免费av网站在线观看 | 五月亚洲| 中文字幕亚洲精品 | 久久精品亚洲 | 青青草国产在线视频 | 亚洲精品久久久久久久久久久 | 国产一级在线视频 | 国产欧美精品 | 中文字幕在线免费看 | 一区在线观看 | 少妇一级毛片 | 黄色片在线播放 | 黄色在线观看免费 | 真实的国产乱xxxx在线 | 超碰免费在线观看 | 日韩二区三区 | 色av导航| 亚洲欧美一区二区三区四区 | 欧美一级视频 | www.麻豆av | 欧美日韩国产一区 | 中文字幕+乱码+中文乱码91 | 99福利视频 | 午夜99 | 久久性视频 | 91麻豆精品国产 | 久久精品一二三 |