【发布时间】:2015-12-28 16:27:44
【问题描述】:
我正在做一个自定义画廊,当您单击一个 div 时,它会更改 div 的 src,所以我这样做:
function change2dd1() {
$("div.videoSel > img").attr("class", "joanamid");
$("div.videoSel > img").attr('src', $('.videoSel2 > img').attr('src'));
}
我还尝试更改 img 的类,这样当我点击它时,我会得到一个全屏版本,我会使用它:
$('.Fullscreen').css('height', $(document).outerWidth() + 'px');
//for when you click on an image
$('.joanamid').click(function () {
var src = $('.joanafull').attr('src'); //get the source attribute of the clicked image
$('.Fullscreen img').attr('src', src); //assign it to the tag for your fullscreen div
$('.Fullscreen').fadeIn();
if(imgChecker.height() > imgChecker.width()) {
$(".Fullscreen img").css({"display":"block", "margin":"5% auto","z-index":"20","top":"0", "width":"30%",
"height":"40%"});
}
});
问题是更改类根本不起作用,它保留了 div 首先拥有的相同类。有什么建议吗?
【问题讨论】:
-
你应该使用
addClass()和removeClass(),而不是尝试编辑属性。
标签: jquery