首先描述一下我的场景。在我的页面上,我有 ID 为 showImage 的 div。在那个div下面有几个拇指。我想在 showImage div 中显示更大的图像,当然无需刷新页面。 这就是我目前所要做的。 为每个图像生成的 html 是
<a href="/Property/GetImage/7">
<img id="7" class="details" width="100" height="100" src="/Property/GetImage/7" alt="">
</a>
我正在获取图像 ID 并将其传递给我的 Controller ,该 Controller 将返回一个图像 (也许我不需要这个,因为我已经在同一页面上有这个图像,但我不知道如何使用它) 要继续, Controller 将返回一个图像,我需要在 showImage div 占位符中以更大的尺寸显示该图像。 这是我的代码
function ShowLargeImage(imageId) {
$.ajax({
url: ('/Home/GetImage'),
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({ id: imageId }),
success: function (result) {
//need to pass result(image)to my div
},
});
}
function onPopUp() {
$(".details").click(function (event) {
var imageId = (this.id);
ShowLargeImage(imageId);
});
}
问题是: 例如,我如何从 js 调用我的 showImage div。 showImage.Show(结果); 这可能吗?
最佳答案
如果您已经有了图像并想在另一个 div 中显示它,您可以这样做
$(".details").click(function (event) {
//clone the clicked image
var clone = $(this).clone();
//change the dimensions
clone.height("150px").width("150px");
//place it in the placeholder
$('div#placeholder').html(clone);
});
关于jquery - 使用js函数的json结果刷新div内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9801993/