是否可以将图像添加到带有类的 div 中,例如当我单击 .img123(img class)
以插入到 .div123(div class)
中时.
有了追加,我点击多少次按钮就是一次添加,我只需要一次。而且它与类(class)无关。
$("#theDiv").append("img id='theImg' src='theImg.png'/>");
有没有类似的函数
('.img123').click(function() {
$('.img123'). adding image only one time into ('.div123');
});
最佳答案
使用.one()
将处理程序附加到元素的事件。每个事件类型的每个元素最多执行一次处理程序。试试这个:
$('.img123').one(function() {
//enter code here
});
关于javascript - 我可以用类将图像添加到 div 中吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22676307/