I have the following code:
我有以下代码:
<li class="k-tile k-state-selected" data-type="f" data-uid="504c365a-fd54-4a9f-adc2-c217ce4dc8fc" role="option" aria-selected="false">
<div class="k-thumb">
<img class="k-image" alt="1.jpg" style="" src="http://doelbewust.nl/img/doelbewust_logo.png">
</div>
<strong>1.jpg</strong>
<span class="k-filesize">206.97 KB</span>
</li>
I want to get the source of a image when I click inside li element. Please guide me on this.
我想在li元素内部单击时获取图像的来源。请指导我这个。
4 个解决方案
#1
Try this:
$('li.k-state-selected').on("click", function(){
var src=$(this).find("img").attr("src");
});
#2
I want to get the source of a image whn i clicked inside li elemen
我希望得到一个图像的来源,我点击了li elemen里面
$('li').click(function(){
alert($(this).find('img').attr('src'));
});
#3
There you go:
你去:
$('li .k-tile').click(function(){//only the li with .k-title class
$(this).find('img .k-image').attr('src'); //only the image with .k-image class
});
#4
Clicking on li, showing img src. Demo
点击li,显示img src。演示
$('.k-tile').on('click', function() {
var img= $('.k-image').attr('src');
alert(img);
})
#1
Try this:
$('li.k-state-selected').on("click", function(){
var src=$(this).find("img").attr("src");
});
#2
I want to get the source of a image whn i clicked inside li elemen
我希望得到一个图像的来源,我点击了li elemen里面
$('li').click(function(){
alert($(this).find('img').attr('src'));
});
#3
There you go:
你去:
$('li .k-tile').click(function(){//only the li with .k-title class
$(this).find('img .k-image').attr('src'); //only the image with .k-image class
});
#4
Clicking on li, showing img src. Demo
点击li,显示img src。演示
$('.k-tile').on('click', function() {
var img= $('.k-image').attr('src');
alert(img);
})