簡體   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