如何根据JavaScript中的条件添加图像 [英] how to add image based on if condition in JavaScript

查看:85
本文介绍了如何根据JavaScript中的条件添加图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我第二次问这个问题,但仍然没有得到答复。任何人请帮我如何根据javascript中的条件插入图像。这是我的代码:

Hi All,
i am asking this question for 2nd time, but still didn''t get the reply. anyone pls help me how to insert image based on if condition in javascript. this is my code:

展开 | 选择 | Wrap | 行号

推荐答案


但document.write()打开一个新窗口如何避免它?
but document.write() opens a new window how to avoid it ?

document.write()没有打开一个新窗口(即 window.open())。如果在页面加载后使用,它会重新创建页面。

document.write() doesn’t open a new window (that’s window.open()). it recreates the page if used after page load.


感谢您的回复。但没有运气,当我尝试使用document.write()时,它消失了当前窗口的细节并在新窗口中显示图像。请告诉我有没有其他方法可以做到这一点?
thanks for the reply. but no luck, when i tried with document.write() it vanishes the details of current window and displays the image in new window. please let me know is there any other way to do this ?
展开 | 选择 | Wrap | 行号



但没有运气,当我尝试使用document.write()时它消失了当前窗口的详细信息,并在新窗口中显示图像。
but no luck, when i tried with document.write() it vanishes the details of current window and displays the image in new window.



这就是我所说的重新创建页面。


that’s what I said with "recreating the page".



i也试过上面的代码,但仍然没有运气
i have tried with above code also but still no luck



当然, document.URL 是只读的(并且不会是一个图像或) document.images 是一个List,而不是一个图像元素。


您需要做的是插入一个< img>元素进入文档树(但由于我没有足够的信息,关于何处和如何,我甚至无法提供演示代码)。


除此之外,字符串没有 .innerHTML 属性。反之亦然,HTMLElements不等于字符串(除非你得到正确的元素字符串)

of course, document.URL is read-only (and wouldn’t be an image either) and document.images is a List, not an image element.

what you would need to do is insert an <img> element into the document tree (but since I don’t have enough information about the where and how, I can’t provide even demo code).

besides that, Strings do not have an .innerHTML property. or vice versa, HTMLElements do not equal Strings (unless you get the element stringification right)


这篇关于如何根据JavaScript中的条件添加图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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