What is the usage of escape in css

藏色散人
Release: 2023-02-01 10:15:43
Original
1516 people have browsed it

escape在css中的使用语法是“escapedStr = CSS.escape(str);”;“CSS.escape()”静态方法返回DOMString包含作为参数传递的转义字符串,主要用作CSS选择器的一部分;其使用示例如“document.querySelector('#' + CSS.escape(id) + ' > img');”。

What is the usage of escape in css

本教程操作环境:Windows10系统、CSS3版、DELL G3电脑

escape在css中用法是什么?

CSS.escape() 静态方法返回 DOMString 包含作为参数传递的转义字符串,主要用作 CSS 选择器的一部分。

语法

escapedStr = CSS.escape(str);
Copy after login

参数

str:The DOMString to be escaped.
Copy after login

实例

基本结果

CSS.escape(".foo#bar")        // "\.foo\#bar"
CSS.escape("()[]{}")          // "\(\)\[\]\{\}"
CSS.escape('--a')             // "--a"
CSS.escape(0)                 // "\30 ",  Unicode 代码点“0”是 30
CSS.escape('\0')              // "\ufffd",  Unicode 替换字符
Copy after login

在上下文使用

要转义一个字符串作为选择器使用, escape()方法可以用于:

var element = document.querySelector('#' + CSS.escape(id) + ' > img');
Copy after login

escape()方法也可以用于转义字符串,它也转义了不严格需要转义的字符:

var element = document.querySelector('a[href="#' + CSS.escape(fragment) + '"]');
Copy after login

推荐学习:《css视频教程

The above is the detailed content of What is the usage of escape in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!