附加列表项内的锚标记 [英] Append anchor tag inside list-item
本文介绍了附加列表项内的锚标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个无序列表:
HTML:
< UL ID =博客>
<立GT;
<一类=vimg的href =/博客/新闻/ 6875583-飓风沙>
&所述; IMG SRC =mydomainvideo_icons.jpg 1542?>
&所述; / A>
< /李>
< A HREF =/博客/新闻/ 6875583-飓风沙>
<强类=titlen>桑迪飓风< / STRONG>
< p =类newsp> LOREM ispum LOREM ispumu ...< / P>
&所述; / A>
<一类=READP的href =/博客/新闻/飓风沙>了解详情< / A>
<立GT;< /李>
<立GT;< /李>
< / UL>
我想改变上述与jQuery的HTML,所以输出将是如下:
< UL ID =博客>
<立GT;
<一类=vimg的href =/博客/新闻/ 6875583-飓风沙>
&所述; IMG SRC =mydomainvideo_icons.jpg 1542?>
&所述; / A>
< A HREF =/博客/新闻/ 6875583-飓风沙>
<强类=titlen>桑迪飓风< / STRONG>
< p =类newsp> LOREM ispum LOREM ispumu ...< / P>
&所述; / A>
<一类=READP的href =/博客/新闻/飓风沙>了解详情< / A>
< /李>
<立GT;< /李>
<立GT;< /李>
这是jQuery的我有但其不工作:
jQuery的:
$(#博客里)。每个(函数(){ 如果($(视频容器)长度方式> 0安培;&安培; $(本)。儿童('IMG')长度== 0){
VAR vidindex = $('。READP')。ATTR('href属性)
$(本).find('。视频容器)删除();
$(本).append('&下;类别=vimg的href =>&下; IMG SRC ={{'video_icons.jpg'| ASSET_URL}}/>&下; / A>') ;
$('。titlen')。appendTo('。vimg')
$(本).find('A')。ATTR(的href,vidindex)
}
$(本).find('IMG')replaceWith(函数(){返回'< IMG SRC ='+ this.src +'/>';});
});
解决方案
附加列表项内的锚标记
块引用>$(#博客),发现(「李先生」)追加。(< A HREF ='#'>有的描述< / A>中);
I have an unordered list:
Html:
<ul id="blogs"> <li> <a class="vimg" href="/blogs/news/6875583-hurricane-sandy"> <img src="mydomainvideo_icons.jpg?1542"> </a> </li> <a href="/blogs/news/6875583-hurricane-sandy"> <strong class="titlen">Hurricane Sandy</strong> <p class="newsp">lorem ispum lorem ispumu...</p> </a> <a class="readp" href="/blogs/news/hurricane-sandy">Read More</a> <li></li> <li></li> </ul>
I would like to alter the html above with jQuery, so the output would be the following:
<ul id="blogs"> <li> <a class="vimg" href="/blogs/news/6875583-hurricane-sandy"> <img src="mydomainvideo_icons.jpg?1542"> </a> <a href="/blogs/news/6875583-hurricane-sandy"> <strong class="titlen">Hurricane Sandy</strong> <p class="newsp">lorem ispum lorem ispumu...</p> </a> <a class="readp" href="/blogs/news/hurricane-sandy">Read More</a> </li> <li></li> <li></li>
This is the jquery I have but its a not working:
jQuery:
$("#blogs li").each(function(){ if ($(".video-container").length > 0 && $(this).children('img').length == 0){ var vidindex = $('.readp').attr('href') $(this).find('.video-container').remove(); $(this).append('<a class="vimg" href=""><img src="{{ 'video_icons.jpg' | asset_url }}"/></a>'); $('.titlen').appendTo('.vimg') $(this).find('a').attr("href", vidindex) } $(this).find('img').replaceWith(function(){ return '<img src="'+this.src+'"/>';}); });
解决方案Append anchor tag inside list-item
$("#blogs").find("li").append("<a href='#'>some Description</a>");
这篇关于附加列表项内的锚标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文