Javascript 克隆的图像元素上的绑定onclick事件
在我看来,我有几个大拇指。图像。 在页面加载时,第一个图像被克隆并加载到相应的div中。之后,每个图像onclick都会在相应的div中以更大的尺寸进行复制 现在我需要在复制的元素上绑定onclick操作,以便为简单起见复制警报hello。 这是我目前掌握的代码Javascript 克隆的图像元素上的绑定onclick事件,javascript,jquery,asp.net-mvc-3,Javascript,Jquery,Asp.net Mvc 3,在我看来,我有几个大拇指。图像。 在页面加载时,第一个图像被克隆并加载到相应的div中。之后,每个图像onclick都会在相应的div中以更大的尺寸进行复制 现在我需要在复制的元素上绑定onclick操作,以便为简单起见复制警报hello。 这是我目前掌握的代码 <div id="detailsRight"> <div id="showImage"> //here will be copied thumb image </div>
<div id="detailsRight">
<div id="showImage">
//here will be copied thumb image
</div>
<div id="thumbImages">
@if (Model.Images == null)
{
<h1> no image </h1>
}
@foreach (var image in Model.Images)
{
<img src="@image.Path" class="details" width="50" height="50" alt="" />
}
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
cloneImages();
});
function cloneImages() {
var imageObject = $("img.details").first();
var clonedObj = $(imageObject).clone();
clonedObj.height("250px").width("300px");
clonedObj.appendTo($("div#showImage"));
$(".details").click(function (event) {
//clone the clicked image
var clone = $(this).clone();
clone.height("250px").width("300px");
//place it in the placeholder
$('div#showImage').html(clone);
});
}
</script>
//这里将复制拇指图像
@如果(Model.Images==null)
{
没有图像
}
@foreach(Model.Images中的var图像)
{
}
$(文档).ready(函数(){
克隆图像();
});
功能克隆图像(){
var imageObject=$(“img.details”).first();
var clonedObj=$(imageObject.clone();
克隆对象高度(“250px”)。宽度(“300px”);
clonedObj.appendTo($(“div#showImage”);
$(“.details”)。单击(函数(事件){
//克隆单击的图像
var clone=$(this.clone();
克隆。高度(“250px”)。宽度(“300px”);
//将其放置在占位符中
$('div#showImage').html(克隆);
});
}
你在找这个吗
$('div#showImage').on('click','img',function(){
alert('Clicked!');
});
你在找这个吗
$('div#showImage').on('click','img',function(){
alert('Clicked!');
});
正是:)需要休息。谢天谢地:)需要休息。谢谢