jquery - 使用js函数的json结果刷新div内容

标签 jquery json

首先描述一下我的场景。在我的页面上,我有 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/

相关文章:

javascript - jquery 动画循环不起作用?

javascript - jQuery promise 对象还有哪些其他类型?

java - 使用 twitter4j 从 StatusJSONImpl 获取 JSONObject

json - 如何用postman和spring boot发送multipartFile和Json

python - django - 发布数据查询字典为空

javascript - 用于动态创建控件的日期选择器

javascript - 如何在javascript中过滤和添加剩余的obj

javascript - 使用 Jquery Mobile 时,HTML A HREF 不断添加 # 和基本 url

android - 如何解析四方类别json

c# - 如何正确使用 javascript 反序列化将 json 字符串转换为复杂对象?