在onclick上获得图像风格

时间:2015-04-29 09:59:59

标签: javascript jquery html css

这是代码:

<ul id="carousel">
    <li><a class="group cboxElement" href="Images/AiringCupboard0_2.jpg">
        <img src="Images/2013042517364073_AiringCupboard0_2.jpg" alt="Image not found" title="AiringCupboard0_2.jpg"
            style="width: 144px; height: 192px; opacity: 1">
    </a></li>
    <li><a class="group cboxElement" href="Images/AiringCupboard0_3.jpg">
        <img src="Images/2013042517364073_AiringCupboard0_3.jpg" alt="Image not found" title="AiringCupboard0_3.jpg"
            style="width: 144px; height: 192px; opacity: 1">
    </a></li>
</ul>

要获取我尝试的特定名称 的的javascript

 var img_name = document.getElementsByClassName('cboxPhoto')[0].nameProp;
 var $img_panel_id = $('#carousel').find('li a img' + img_name);
 $img_panel_id.parent().attr('style');

让我们说img_name是AiringCupboard0_3.jpg然后如何获取该图片标签的样式

2 个答案:

答案 0 :(得分:1)

您可以通过标题获取图片......

$("#carousel").click(function() {
    $(this).find('img[title="AiringCupboard0_3.jpg"]').attr("style");
});

答案 1 :(得分:0)

var getCarouselImg = document.querySelectorAll('#carousel li');
for(var i = 0; i < getCarouselImg.length; i++){
    getCarouselImg[i].onclick = function(){
        console.log(this.querySelector('img').getAttribute('style'));
    }
}