我不确定这是否正确 $('#bigImage').attr("data-big", LargeImagePath);
但同样的语句适用于 '源代码'
。
即。在 JSP 上,我得到了 mediumImagePath
的值,但不大可能 .attr
不会在 data-big
的情况下使用,所以我应该使用什么大数据
。
xyz.js
function getImageDetails(mediumImagePath, LargeImagePath) {
alert(mediumImagePath+"_______"+mediumImagePath);
jQuery.ajax({
type : 'GET',
url : 'productDetailsPage.do',
data : {},
success : function(data) {
$('#bigImage').attr("src", mediumImagePath);
$('#bigImage').attr("data-big", LargeImagePath);
alert(data);
$("#productListPage").hide();
$("#productDetailsPage").show();
}
});
}
这是我尝试设置这些值的 div
:
Abc.Jsp
<div class="view-product">
<img id="bigImage" class="fancybox" src=""
data-big="images/home/suitlarge.jpg" />
<h3>ZOOM</h3>
</div>
Productdiv.jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<div>
<c:forEach items="${products}" var="products">
<div class="col-sm-4">
<div class="product-image-wrapper">
<div class="single-products">
<div class="productinfo text-center">
<img src="${products.smallImage}" onclick="getImageDetails('${products.mediumImage}', '${products.largeImage}');" alt="${products.productId}productImage" />
<h2>${products.allPrice}</h2>
<p>${products.name}</p>
</div>
</div>
<ul class="nav nav-pills nav-justified">
<li><a href=""><i class="fa fa-plus-square"></i>Add to
Wishlist</a></li>
</ul>
</div>
</div>
</c:forEach>
</div>
请帮忙解释一下哪里出了问题。
最佳答案
当你想访问 data
属性时,你应该使用 data
而不是 attr
因此您的代码应该类似于 $('#bigImage').data("big", LargeImagePath);
这是一个完整的例子:
<head runat="server">
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
var big = $("#bigImage").data("big");
alert(big);
});
</script>
</head>
<body>
<img id="bigImage" class="fancybox" src="" data-big="images/home/suitlarge.jpg" />
</body>
关于javascript - 为什么这里没有设置Large Image Path?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35403421/