Detailed explanation of how to handle special symbols in jQuery selectors

小云云
Release: 2017-12-29 10:10:05
Original
1664 people have browsed it

本文主要和大家介绍详解jQuery选择器中的特殊符号如何处理。一般情况下,在jQuery选择器中,我们很少会用到诸如“.”、“#”、“(”、“[”等特殊字符,因为根据W3C规定,HTML文档中属性的值是不能包含有这些个特殊字符的,但是在实际应用中,偶尔也会遇到表达式中含有“#”和“.”等特殊字符,那么是如何处理这些个特殊字符的呢?

HTML代码:


aa

bb

Copy after login

Jquery代码:


var $id_a = $('#id.a');//jQuery对象,实际上是没取到元素的 var $id_b = $('#id#b');//jQuery对象,实际上是没取到元素的 alert( $id_a.length);//输出0 alert( $id_b.length);//输出0 var $id_right_a = $('#id\\.a');//jQuery对象,对特殊字符,我们转义一下 var $id_right_b = $('#id\\#b');//jQuery对象,对特殊字符,我们转义一下 alert( $id_right_a.html());//正确输出"aa" alert( $id_right_b.html());//正确输出"bb"
Copy after login

相关推荐:

Oracle字符串中包含数字、特殊符号的排序问题解决方法

get请求传特殊符号的问题

JavaScript实现输入字符串是否包含特殊符号或表情的方法介绍

The above is the detailed content of Detailed explanation of how to handle special symbols in jQuery selectors. 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 Recommendations
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!