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

我可以在 queryselector() 中為 CONTAINS 使用屬性選擇

Can I use an attribute selector for CONTAINS in queryselector()?(我可以在 queryselector() 中為 CONTAINS 使用屬性選擇器嗎?)
本文介紹了我可以在 queryselector() 中為 CONTAINS 使用屬性選擇器嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想根據 href 屬性的子字符串選擇一個元素.

我最近發布了一個問題,我收到了一個基于開始于"的答案:

document.querySelector('#utility-menu a[href^="/email_check?lang="').textContent.trim();

但實際上,從一個頁面到另一個頁面的唯一常量是 href 屬性中的 "lang=".所以 /email_check? 是特定于頁面的,所以我不能在所有頁面上使用這個變量.

是否可以修改我的選擇器以返回任何 <a> 元素的 textContent,其中包含子字符串 "lang="?

解決方案

所有 CSS 選擇器都記錄在 MDN 并在 W3C CSSWG 選擇器級別 4 概述中指定1 (存檔鏈接).

你需要的是

#utility-menu a[href*="lang="]

<塊引用>

<頭>
模式代表
E[foo*=bar"]一個 E 元素,其 foo 屬性值包含子字符串 bar.


1:CSSWG 目前的 CSS 選擇器模塊工作是選擇器級別 4.并非所有瀏覽器都支持其所有功能.4 級草案包括從 1 級到 4 級的所有內容.觀看級別"表列.今天的瀏覽器至少支持 Level 3,但請查看 兼容性表在 MDN 上確定.

I would like to select an element based on a substring of href attribute.

I posted a question recently where I received an answer based on "starts with":

document.querySelector('#utility-menu a[href^="/email_check?lang="').textContent.trim();

But actually, the only constant from page to page will be "lang=" within the href attribute. So /email_check? is page specific so I cannot use this variable on al pages.

Is it possible to modify my selector to return the textContent of any <a> element with the substring "lang=" within it?

解決方案

All CSS selectors are documented on MDN and specified in the W3C CSSWG Selectors Level 4 overview1 (Archived link).

The one you need is

#utility-menu a[href*="lang="]

Pattern Represents
E[foo*="bar"] An E element whose foo attribute value contains the substring bar.


1: The CSSWG’s current work of the CSS Selectors Module is Selectors Level 4. Not all of its features are supported in all browsers. The Level 4 draft includes everything from Level 1 to Level 4. Watch the "Level" table column. Today’s browsers support at least up to Level 3, but check the compatibility tables on MDN to be sure.

這篇關于我可以在 queryselector() 中為 CONTAINS 使用屬性選擇器嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Style every third element?(每隔三個元素設置樣式?)
Why shouldn#39;t I use ID selectors in CSS?(為什么我不應該在 CSS 中使用 ID 選擇器?)
What does img[class*=quot;alignquot;] mean in CSS?(CSS 中的 img[class*=“align] 是什么意思?)
CSS: Last element on line(CSS:最后一個元素)
How do I select every other div class element using just CSS (no js)(如何僅使用 CSS(無 js)選擇所有其他 div 類元素)
Tool for checking unused CSS selectors?(檢查未使用的 CSS 選擇器的工具?)
主站蜘蛛池模板: 午夜视频在线观看一区二区 | 国产精品久久久久久妇女6080 | 超碰精品在线 | 男人天堂午夜 | 欧美日韩电影一区二区 | 在线国产一区 | 久久成人精品一区二区三区 | 亚洲国产区 | 91精品国产一区 | 久久久亚洲一区 | 可以免费看的毛片 | 欧美日本韩国一区二区 | 日本成人中文字幕 | 欧美日韩专区 | 欧美一级二级视频 | 国产精品一区二区三区久久 | 久久aⅴ乱码一区二区三区 亚洲欧美综合精品另类天天更新 | 精品国产欧美在线 | 国产福利一区二区 | 国产在线精品一区二区三区 | 欧美成人影院在线 | 精品视频一区二区三区在线观看 | 三级在线免费 | 成人欧美一区二区三区黑人孕妇 | 日韩精品极品视频在线观看免费 | 亚洲一区| 久热电影| 欧美日韩视频在线 | 91亚洲欧美| 91国产精品 | 久久精品国产久精国产 | 国产精品爱久久久久久久 | 毛片av免费看 | 日本网站免费在线观看 | 日韩手机视频 | 黄色网址大全在线观看 | 欧美日韩国产高清 | 日本小电影网站 | 色综合99| 日韩中文欧美 | 国产精品不卡一区二区三区 |