jQuery-循环特定的DIV和转换
下面是当前可用的HTML代码。可能有多个DIV的类为“ow\u video\u list\u item ow\u small”jQuery-循环特定的DIV和转换,jquery,loops,youtube,Jquery,Loops,Youtube,下面是当前可用的HTML代码。可能有多个DIV的类为“ow\u video\u list\u item ow\u small” 场地1 我想修改这个HTML,如下所示 <div class="ow_video_list_item ow_small"> <img rel="xVrJ8DxECbg" src="http://img.youtube.com/vi/xVrJ8DxECbg/default.jpg"> <div class="ow_vide
场地1
我想修改这个HTML,如下所示
<div class="ow_video_list_item ow_small">
<img rel="xVrJ8DxECbg" src="http://img.youtube.com/vi/xVrJ8DxECbg/default.jpg">
<div class="ow_video_item_title">
<a href="http://www.site1.com">Site 1</a>
</div>
</div>
PS:IMG src属性的格式不会更改。值“xVrJ8DxECbg”是Youtube中视频的视频ID。这是我的代码。请建议是否有其他更好的解决方案
$($(".ow_video_list_item").find("div")).each(function(){
// do watever you want with divs
});
$( "div .ow_video_list_item").each(function(){
$imgSrc = $(this).children("a").children("img").attr("src");
$videoId = $imgSrc.split("/")[4];
$videoLink = $(this).children("a").attr("href");
$linkTitle = $(this).children("div .ow_video_item_title").text();
$(this).children("a").empty();
$(this).prepend('<img rel="' + $videoId + '" src="' + $imgSrc + '"/>');
$(this).children("div .ow_video_item_title").empty().prepend
('<a href="' + $videoLink + '">'+ $linkTitle + '</a>');
});
$(“div.ow\u video\u list\u item”)。每个(函数(){
$imgSrc=$(this).children(“a”).children(“img”).attr(“src”);
$videoId=$imgSrc.split(“/”[4];
$videoLink=$(this.children(“a”).attr(“href”);
$linkTitle=$(this).children(“div.ow\u video\u item\u title”).text();
$(this.children(“a”).empty();
$(this.prepend(“”);
$(this).children(“div.ow\u video\u item\u title”).empty().prepend
('');
});
我想要的是通过从SRC url获取视频ID来转换内容。然后需要获取锚标记SRC属性,然后获取url参数,然后重新排列div。要获取URL参数,此链接很有用,谢谢@Meraj我找到了解决方案。@LuisTellez:在Google的帮助下,我使用each()函数获得了类的所有DIV。我不知道如何继续获取视频Id和转换te child DIV并删除实际标记。您的帮助将非常有用,因为我是JQueryTanks@LuisTellez的新手。这是我第一个完整的jQuery代码。:)再次感谢。
$( "div .ow_video_list_item").each(function(){
$imgSrc = $(this).children("a").children("img").attr("src");
$videoId = $imgSrc.split("/")[4];
$videoLink = $(this).children("a").attr("href");
$linkTitle = $(this).children("div .ow_video_item_title").text();
$(this).children("a").empty();
$(this).prepend('<img rel="' + $videoId + '" src="' + $imgSrc + '"/>');
$(this).children("div .ow_video_item_title").empty().prepend
('<a href="' + $videoLink + '">'+ $linkTitle + '</a>');
});