简体   繁体   English

Internet Explorer jQuery:包含问题

[英]Internet Explorer jquery :contains issue

I'm trying to parse a simple xml document with jQuery. 我正在尝试使用jQuery解析一个简单的xml文档。 Does anyone know why the following works fine in Chrome and Firefox but not in Internet Explorer (7 and 8)? 有谁知道为什么以下内容在Chrome和Firefox中可以正常运行,而在Internet Explorer(7和8)中却不能正常运行?

var selBunit = $("#bunit").val();
$(bunitXml).find('bunit bname:contains('+selBunit+')').parent().find('team')

Below is a snippet of the xml. 以下是xml的代码段。 So basically I'm trying to return all "team" elements for the selected business unit ("bunit"). 因此,基本上,我试图返回所选业务部门(“部门”)的所有“团队”元素。

<bunit>
<bname>Unit 1</bname>
<teams>
    <team>
        <name>Team 1</name>
        <jobtitles>
            <jobtitle approval="false">Jobtitle 1</jobtitle>
        </jobtitles>
    </team>
    <team>
        <name>Team 2</name>
        <jobtitles>
            <jobtitle approval="false">Jobtitle 2</jobtitle>
        </jobtitles>
    </team>                         
</teams>
</bunit>

At first I tried 起初我尝试

$(bunitXml).find('bunit bname:contains($("#bunit").val())').parent().find('team')

which doesn't work at all. 这根本不起作用。 After some googling I tried the following: 经过一番谷歌搜索后,我尝试了以下操作:

var selBunit = $("#bunit").val();
$(bunitXml).find('bunit bname:contains('+selBunit+')').parent().find('team')

which returns all team elements fine in Chrome and Firefox but not in Internet Explorer. 在Chrome和Firefox中返回的所有团队元素都很好,但在Internet Explorer中却没有。 I can't get my head around it. 我无法解决这个问题。 I'm pretty new to jQuery so I might go about it completely wrong so any suggestions would be appreciated. 我是jQuery的新手,所以我可能会完全错了,所以任何建议都将不胜感激。 Thanks a bunch 谢谢一大堆

var selBunit = $("#bunit").val();
$(bunitXml).find('bunit bname:contains('+selBunit+')').parent().find('team')

If I m understanding well, selBunit is a string so you should use : 如果我很了解,selBunit是一个字符串,所以您应该使用:

var selBunit = $("#bunit").val();
$(bunitXml).find("bunit bname:contains('"+selBunit+"')").parent().find('team')

or 要么

 $(bunitXml).find("bname:contains('" +selBunit+ "')").find('team');

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

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