JavaScript document.write display image

 In addition to outputting text strings, the feature of JavaScript document.write can also output content that contains HTML tags. This article is to use this feature to enable JavaScript to also output images to web pages, allowing traditional HTML img image insertion methods There are richer changes. The actual part must be combined with JavaScript document.write and HTML img tags. Almost all mainstream browsers support document.write to display pictures. Please see the two basic syntaxes required. .


Document.write and HTML img basic syntax
Scriptgrammar structure
Document.writedocument.write('Write the text you want to present here');
HTML img
<img src="Picture URL put here">

As long as these two grammars are combined, images can be easily output to web pages via JavaScript document.write .

JavaScript document.write display image example
<script language="javascript">
document.write('<img src="images/logo.png">');
</script>
The document.write in the example uses simple HTML img image tag syntax to achieve the effect of outputting images. In addition, other effects can be added, such as adding image hyperlinks or adding borders to images. Effects, these special effects are made by combining document.write with HTML tags.

Post a Comment

0 Comments