Mootools选择器麻烦

时间:2011-04-28 20:19:51

标签: javascript mootools css-selectors

我有这个HTML:

    <div id="link-thumbs-list">
<img src="image.php?f=http://www.jetphotos.net/trans.gif&amp;h=72&amp;w=128" />
<img src="image.php?f=http://www.jetphotos.net/logo-nb.jpg&amp;h=72&amp;w=128" />
<img src="image.php?f=http://www.jetphotos.net/trans.gif&amp;h=72&amp;w=128" />
</div>

我需要选择f =(文件url)到每个imgs的src属性中.. 我能怎么做?? Thanksss

2 个答案:

答案 0 :(得分:3)

就是这样:

var urls = document.getElements("#link-thumbs-list img").get("src").map(function(el) {
    return el.replace("image.php?f=", "").split("&")[0];
});

console.log(urls);

输出:

["http://www.jetphotos.net/trans.gif", "http://www.jetphotos.net/logo-nb.jpg", "http://www.jetphotos.net/trans.gif"]

答案 1 :(得分:0)

$$("#link-thumbs-list img").each(function(elem) {
    var m = elem.get("src").match(/f=([^&]*)&/);
    if (m && m[1]) {
        elem.set("src", m[1]);
    }
});