JavaScript 警报中的图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17268197/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 07:42:57  来源:igfitidea点击:

Image In JavaScript Alert

javascriptimagealert

提问by Ishan Jain

I know it's a unwise question but if it's possible -

我知道这是一个不明智的问题,但如果可能的话——

Can we show a image in JavaScript alert box?

我们可以在 JavaScript 警告框中显示图像吗?

If it's possible, How can we do this?

如果可能,我们该怎么做?

回答by techfoobar

No.You cannot display an image inside JavaScript's native alert()box.

不可以您不能在 JavaScript 的本机alert()框中显示图像。

Side note: alert()displays what's given to it as input as pure text, meaning you cannot pass a string containing an <img>tag to it and expect it to display an image - it will instead display the string "<img src...>".

旁注alert()将提供给它的内容显示为纯文本,这意味着您不能将包含<img>标签的字符串传递给它并期望它显示图像 - 它会显示字符串"<img src...>"

回答by aaron34weston

It's not possible with vanilla JavaScript, although you could use the <div>element, Bootstrap modals, or JavaScript libraries.

尽管您可以使用<div>元素、Bootstrap 模式或 JavaScript 库,但使用 vanilla JavaScript 是不可能的。

Bootstrap example: https://www.w3schools.com/bootstrap/bootstrap_modal.asp

Bootstrap 示例:https: //www.w3schools.com/bootstrap/bootstrap_modal.asp

回答by Chanckjh

no it's not possible but why not make something that looks like it. for example a popup.

不,这是不可能的,但为什么不做一些看起来像它的东西。例如弹出窗口。

回答by Raptor

JS alert box has no place to place image, but you can create your own alert style, as you wish, e.g. show a DIV at screen center with background dimmed (just like Facebook, and many other sites)

JS 警报框没有放置图像的地方,但您可以根据需要创建自己的警报样式,例如在屏幕中心显示一个背景变暗的 DIV(就像 Facebook 和许多其他网站一样)

回答by CloudyMarble

Its not possible using the normal alert function, you may consider trying this using the jQuery Dialogto simulate the alertbox

它不可能使用正常的警报功能,您可以考虑使用jQuery Dialog来模拟警报框

回答by Nemus

No, you can't display image with js alert box, but you can wit jquery. Maybe this plugin would be interesting for you: WowWindow plugin

不,您无法使用 js 警报框显示图像,但您可以使用 jquery。也许这个插件对你很有趣: WowWindow plugin

回答by user3537606

It's not possible, but you can show the img in a modal.

这是不可能的,但您可以在模态中显示 img。