使用 jquery 在 div 中添加图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14830014/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
add image/s inside a div with jquery
提问by user2064285
Every time I click on a button
<button class="xx type="submit" id="add_football">Add</button>
每次我点击一个按钮
<button class="xx type="submit" id="add_football">Add</button>
I want to add a image(<img src="img/door-right.png">
)inside the
<div class="ball_footballbox"><img src</div>
我想在<img src="img/door-right.png">
里面添加一个图像()
<div class="ball_footballbox"><img src</div>
How do I do that with jQuery?
我如何用 jQuery 做到这一点?
回答by arnaud
Or
$('<img src="img/door-right.png">').appendTo(".ball_footballbox");
或者
$('<img src="img/door-right.png">').appendTo(".ball_footballbox");
回答by Sudip Pal
Try this
尝试这个
$(".ball_footballbox").append('<img src="img/door-right.png">');
wrap this in a function and call this function on click of button action.
将其包装在一个函数中,并在单击按钮操作时调用此函数。
回答by Pandian
try like below... it will work
尝试如下...它会工作
HTML :
HTML :
<button class="xx" type="submit" id="add_football">Add</button>
<div class="ball_footballbox"></div>
JQuery :
查询:
$("#add_football").click(function() {
$('.ball_footballbox').prepend('<img id="theImg" src="img/door-right.png" prepended="yes"/>')
});
Fiddle : http://jsfiddle.net/RYh7U/73/