在jQuery中创建img [英] Create img in jQuery

查看:142
本文介绍了在jQuery中创建img的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在jQuery中创建img标签并将其设置为只有某些div的内容?

How to create img tag in jQuery and set it as only content of some div?

如果目标div有一些内容,请替换它并放置动态创建的img标签。

If target div has some content, replace it and put dynamically created img tag.

以下是我的尝试:

        $(".someClass").click(function(){

             var $img = $('<img allowfullscreen  ></img>', {
                'width': 650,
                'height': 580,              
                'src': $(this).find('img').attr('data')
             });
             $('#someId').html($img);

        });

谢谢。

推荐答案

var $img=$("<img />",{"src":url});
$(target_id).html($img);

这篇关于在jQuery中创建img的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆