IE与字符串匹配

发布于 2024-10-06 17:37:26 字数 453 浏览 0 评论 0原文

我试图获取页面上所有链接的数组,其 href 与特定字符串(网址的一部分)匹配。此方法适用于除 IE 之外的所有浏览器,我不知道为什么。

var url = '/work.php?subsection=1';
a = $('clients').getElements('a[href^='+url+']');
alert(a.length);

我正在使用 Mootools,它可以解释 $('clients').getElements() 位。

在所有浏览器中,除了 IE a.length 返回 10。IE 返回 0。有人知道为什么吗?

值得一提的是,我只需要 href 的第一部分来匹配。因此 应该匹配。

I'm trying to get an array of all links on a page whose href matches a specific string (part of the url). This method works in all browsers but IE, and I'm not sure why.

var url = '/work.php?subsection=1';
a = $('clients').getElements('a[href^='+url+']');
alert(a.length);

I'm using Mootools which would explain the $('clients').getElements() bit.

In all browsers but IE a.length returns 10. IE returns 0. Anyone know why??

It's worth mentioning that I only need the first part of the href to match. So <a href="/work.php?subsection=1&project=11"></a> should match.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

桃酥萝莉 2024-10-13 17:37:27

如果不知道您使用的是哪个版本的 Mootools,也没有看到页面的标记,就很难给出答案。

IE 是否可以将 URL 视为完全合格的?换句话说,IE 是否可以相信 URL 以 http://yourdomain.com/ 开头,而不是以 /work.php?subsection=1 开头?

编辑:作为解决方法,您可以使用 [att*=val] 选择器,它根据属性是否仅包含指定值进行匹配。如果您认为您的网址可能在开头以外的其他位置包含 /work.php?subsection=1,并且您确实不想匹配这些内容,则可以抛出您的域名也在那里。

Without knowing which version of Mootools you're using, and without seeing the markup of the page, it's difficult to give an answer.

Could IE be treating the URLs as though they are fully qualified? In other words, instead of starting with /work.php?subsection=1, could IE believe the URLs start with http://yourdomain.com/?

Edit: As a work around, you could use the [att*=val] selector, which matches based on whether attribute simply contains the specified value. If you feel that your URL might contain /work.php?subsection=1 somewhere other than the beginning, and you really don't want to match those, you could throw your domain in there, too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文