繁体   English   中英

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

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

我在与jQuery 3.3.1一起使用的find函数中有一个选择器,而在3.4.0和3.4.1中则没有。 我在使用$ .parseXML的xhtml jQuery文档对象上使用它。 我正在使用完整版的jQu​​ery。

我查看了jQuery changelogs,没有发现应该影响到此的内容,以及github上的源代码更改。

我已经使用.class和#id测试了查找结果,它可以工作,但是ID是动态的,因此我需要按属性名称进行搜索。 我还需要操纵多个跨度,这就是为什么我需要一个.each(function)的原因。 当前,我们正在冻结对jQuery 3.3.1的依赖,因为它可以按预期工作,但在3.4.0+中甚至没有输入该函数。

作品:

 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> 

不起作用:

 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> 

问题在这里解决了。 3.4.0+摆脱了嘶嘶声。

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

“新版本的jQuery使用的querySelectoAll不会发出嘶嘶声。如此多的嘶嘶声语法已不再起作用。

命名空间属性查询可能是在嘶嘶声中实现的。” -jakecigar

暂无
暂无

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

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