简体   繁体   English

带有转义字符的jQuery查找功能在最新版本中不起作用

[英]jQuery find function with escape characters not working in latest version

I have a selector in a find function that works with jQuery 3.3.1 and before that doesn't in 3.4.0 and 3.4.1. 我在与jQuery 3.3.1一起使用的find函数中有一个选择器,而在3.4.0和3.4.1中则没有。 I am using it on an xhtml jQuery document object that I have used $.parseXML on. 我在使用$ .parseXML的xhtml jQuery文档对象上使用它。 I am using the full version of jQuery. 我正在使用完整版的jQu​​ery。

I have looked into the jQuery changelogs and see nothing that should affect this, as well as in the source changes on github. 我查看了jQuery changelogs,没有发现应该影响到此的内容,以及github上的源代码更改。

I have tested the find with .class and #id and it works, but the IDs will be dynamic so I need to search by attribute name. 我已经使用.class和#id测试了查找结果,它可以工作,但是ID是动态的,因此我需要按属性名称进行搜索。 There will also be multiple spans that I need to manipulate which is why I need a .each(function). 我还需要操纵多个跨度,这就是为什么我需要一个.each(function)的原因。 Currently we are freezing our dependency to jQuery 3.3.1 because it works as expected but in 3.4.0+ it doesn't even enter the function. 当前,我们正在冻结对jQuery 3.3.1的依赖,因为它可以按预期工作,但在3.4.0+中甚至没有输入该函数。

Works: 作品:

 const xmlDoc = $.parseXML(`<?xml version="1.0" encoding="windows-1252" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns:dd="DynamicDocumentation"> <head> <title></title> </head><body><span dd:drop_list_uuid="9999">mydrop1</span></body></html>`); const $xml = $(xmlDoc).find('body'); $xml.find('span[dd\\\\:drop_list_uuid]').each(function() { console.log($(this).text()) }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> 

Does not work: 不起作用:

 const xmlDoc = $.parseXML(`<?xml version="1.0" encoding="windows-1252" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns:dd="DynamicDocumentation"> <head> <title></title> </head><body><span dd:drop_list_uuid="9999">mydrop1</span></body></html>`); const $xml = $(xmlDoc).find('body'); $xml.find('span[dd\\\\:drop_list_uuid]').each(function() { // This is the line that doesn't work console.log($(this).text()) }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> 

Problem solved here. 问题在这里解决了。 3.4.0+ gets rid of sizzle. 3.4.0+摆脱了嘶嘶声。

https://forum.jquery.com/topic/jquery-find-function-with-escape-characters-not-working-in-latest-version#14737000008103091 https://forum.jquery.com/topic/jquery-find-function-with-escape-characters-not-working-in-latest-version#14737000008103091

"the new versions of jQuery use querySelectoAll without sizzle. So many sizzle syntaxes don't work anymore. “新版本的jQuery使用的querySelectoAll不会发出嘶嘶声。如此多的嘶嘶声语法已不再起作用。

A namespaced attribute query was probably implemented in sizzle." -jakecigar 命名空间属性查询可能是在嘶嘶声中实现的。” -jakecigar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM