开发者

IE and string matching

开发者 https://www.devze.com 2023-01-29 04:28 出处:网络
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.

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消