[英]adding html image using jquery to div/table
i'm new to JQuery and currently using it in Visual Studio 2013. 我是JQuery的新手,目前在Visual Studio 2013中使用它。
I want to ask how do I add img tag into a table or div using JQuery? 我想问一下如何使用JQuery将img标签添加到表或div中?
Ie. 就是 i have a div and i want to dynamically create image using jquery.
我有一个div,我想使用jquery动态创建图像。 OR i have a dynamically created table in a dynamically created div, and I want to add an image to one of its row.
或者我在动态创建的div中有一个动态创建的表,并且我想向其行之一添加图像。
I've tried this in jsfiddle ( http://jsfiddle.net/3C7UD/1/ ) 我已经在jsfiddle( http://jsfiddle.net/3C7UD/1/ )中尝试过
$("#divid").append('<table>
<tr>
<td>asdasdasd</td>
<td><img src:"https://www.google.com/images/srpr/logo11w.png" width:"225px" height:"225px" /></td>
</tr>
</table>');
$('#divid').append('<img src:"' + imgLink + '" width:"225px" height:"225px" />');
but no image.. I also have tried that in visual studio project but the same (no image). 但没有图像..我也曾在Visual Studio项目中尝试过,但相同(无图像)。
I can't found any tutorial about adding image, and the solutions I found in this forum haven't work for me by far.... 我找不到任何有关添加图像的教程,并且在该论坛中找到的解决方案到目前为止对我还行不通。
You wrote <img src:"..." />
instead of <img src="..." />
which is the reason why your code isn't showing the image: 您编写了
<img src:"..." />
而不是<img src="..." />
,这就是您的代码未显示图像的原因:
Corrected fiddle : http://jsfiddle.net/Zword/3C7UD/3/ 已更正小提琴: http : //jsfiddle.net/Zword/3C7UD/3/
Corrected part of code: 更正的部分代码:
$("#divid").append('<table><tr><td>asdasdasd</td><td><img src="http://blog.sckyzo.com/wp-content/google-small.png" width:"225px" height:"225px" /></td></tr></table>');
$('#divid').append('<img src="' + imgLink + '" width:"225px" height:"225px" />');
HTML attributes are specified with =
, not :
. HTML属性用
=
而不是:
来指定。
$("#divid").append('<table><tr><td>asdasdasd</td><td><img src="http://blog.sckyzo.com/wp-content/google-small.png" width="225px" height="225px" /></td></tr></table>');
$('#divid').append('<img src="' + imgLink + '" width="225px" height="225px" />');
Updated demo: http://jsfiddle.net/3C7UD/5/ 更新的演示: http : //jsfiddle.net/3C7UD/5/
try changing this 2 lines: 尝试更改这2行:
var img = "<img src='"+imgLink+"' />";
and the last one: 最后一个:
$('#divid').append(img);
Change your code to : 将您的代码更改为:
$("#divid").append('<table>
<tr>
<td>asdasdasd</td>
<td><img src:"https://www.google.com/images/srpr/logo11w.png" style="width:225px; height:225px" /></td>
</tr>
</table>');
$('#divid').append('<img src:"' + imgLink + '" style = "width:225px;height:225px" />');
Change your: 改变你的:
><img src:"
to 至
><img src="
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.