发现jquery库的关键字冲突,造成了隐形BUG!(附代码)
在以下的XML内容里,jquery对于 “source” 这个关键字里的节点内容,在用find查找时无法找到其内容,如果换其它名称,就能找到内部包含的字符串信息,希望各位在开发的时候注意一下,这个隐形
BUG我也是测试N遍后,才察觉到!
1 <listen>
2 <source>Women are on their way to holding more than half of all American jobs.</source>
3 <translate>美国女性正逐步占据全美过半的工作岗位。</translate>
4 </listen>
2 <source>Women are on their way to holding more than half of all American jobs.</source>
3 <translate>美国女性正逐步占据全美过半的工作岗位。</translate>
4 </listen>
jquery的find找寻代码
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 function ReadArticleContetn() {
2 var ajaxUrl = "http://....../file.xml";
3
4 //获取听写信息,返回XML结构
5 $.ajax({ url: ajaxUrl, type: "GET", dataType: "XML", error: XmlReadError, success: XmlReadCompleted });
6 }
7
8 //读取XML内容成功
9 function XmlReadCompleted(xml) {
10 XmlReadStatus = true;
11 Listen.Source = $(xml).find("source").text();
12 Listen.Translate = $(xml).find("translate").text();
13 }
2 var ajaxUrl = "http://....../file.xml";
3
4 //获取听写信息,返回XML结构
5 $.ajax({ url: ajaxUrl, type: "GET", dataType: "XML", error: XmlReadError, success: XmlReadCompleted });
6 }
7
8 //读取XML内容成功
9 function XmlReadCompleted(xml) {
10 XmlReadStatus = true;
11 Listen.Source = $(xml).find("source").text();
12 Listen.Translate = $(xml).find("translate").text();
13 }