jquery map()方法 执行次数变少。

2015-10-14 16:21:27 +08:00
 tt210

在 chrome 上写了个油猴脚本,用来转换目标网站的链接,用 jquery 获取的链接是 10 个,但是用 myurl.map()方法却只能执行 7 次,真是花了狗了,请求大神指点,谢谢。
部分代码如下:

var SourceUrls = $('#content_left .g'),
     Re = /(.*?)\//,
     c = 0 ;
SourceUrls.map(function () {
    SourceUrl = (Re.exec($(this).text()))[1];
    c++;
    alert(c);
    alert(SourceUrl);
});
1469 次点击
所在节点    问与答
5 条回复
chairuosen
2015-10-14 16:33:30 +08:00
need demo
tt210
2015-10-14 16:45:44 +08:00
我去,又正常了。虾米情况啊。我再测试下。谢谢楼上。
tt210
2015-10-14 16:57:21 +08:00
```
// ==UserScript==
// @name My Fancy New Userscript
// @namespace http://your.homepage/
// @version 0.1
// @description enter something useful
// @author You
// @grant none
// @match https://www.baidu.com/*
// @require http://www.w3school.com.cn/jquery/jquery.js
// ==/UserScript==
var SourceUrls = $('#content_left .g'),
SourceUrl,
Re = /(.*?)\//,
c = 0;
SourceUrls.map(function () {
SourceUrl = (Re.exec($(this).text()))[1];
c++;
alert('执行次数:' + c + '\n' + 'SourceUrls 元素数量:' + SourceUrls.length);
});
alert('执行次数:' + c + '\n' + 'SourceUrls 元素数量:' + SourceUrls.length); //这个不会执行,为什么?
tt210
2015-10-14 16:59:12 +08:00
大家帮忙测试下,正常不?刚才测试还是有问题。好像加了那句正则匹配就出错。
tt210
2015-10-14 17:01:38 +08:00

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/227993

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX