【发布时间】:2011-05-21 22:17:50
【问题描述】:
如何在 jQuery 中找到所有链接(没有锚点)并将它们按照出现的顺序放在一个列表中。
例如:
Lorem ipsum dolor sat amet,consecteturadipiscing elit。 Donecsit amet ipsum ut justo bakeum hendrerit ultricies。
所以,这将变成:
Lorem ipsum
坐下,
肥胖精英。
sit amet ipsum ut justo balloon 亨德利特。
基本上我在我的网站上使用 embed.ly,因此当用户填写表单时,youtube/flickr 链接会自动出现在他创建它们的位置。我遇到的问题是 youtube 视频的缩略图似乎太大,并且无法正确切换(即我希望用户单击缩略图以显示视频)。 (因此,例如,如果用户单击 dolar 链接,则 youtube 视频应出现在其下方,就像在 embed.ly 示例中一样)。
我在服务器端使用 php 和 php markdown。
embedly的查询代码如下:
<script type="text/javascript">
$(document).ready(function() {
$("a").embedly({}, function(oembed, dict){
if ( oembed == null)
alert("no embedly content found");
var output = "<a class='embedly' href='#'><img src='"+oembed.thumbnail_url+"' /></a><span>"+oembed.title+"</span>";
output += oembed['code'];
$(dict["node"]).parent().html( output );
});
var anchors = $("a"); anchors.embedly(); anchors.filter("[href*=flx.me]").addClass("googlenl");
$('a.embedly').live("click", function(e){
e.preventDefault();
$(this).parents('li').find('.embed').toggle();
});
});
</script>
我的网站在添加视频链接时生成的 html 是:
> <div id="content">
> <div class="youtube">
> <p><a class="embedly" href="#"><img
> src="phpForum_files/hqdefault.jpg"></a><span>UEFAChanpions
> League 2005-2006 RealMadrid vs Arsenal
> 2ndleg</span><div
> class="embed"><object height="360"
> width="640"><param name="wmode"
> value="opaque"><param name="movie"
> value="http://www.youtube.com/v/7aPGa9Gqj2c?fs=1"><param
> name="allowFullScreen"
> value="true"><param
> name="allowscriptaccess"
> value="always"><embed
> src="phpForum_files/7aPGa9Gqj2c.swf"
> type="application/x-shockwave-flash"
> allowscriptaccess="always"
> allowfullscreen="true" wmode="opaque"
> height="360"
> width="640"></object></div></p>
> </div> </div>
抱歉,问题太长了。干杯。
【问题讨论】:
-
链接是什么,如果它们不是锚点?
-
@David 我认为 OP 只想捕获 URI 链接而不是“书签”(哈希链接)
-
是的,对不起,应该只说 URI...