如何在提示框或确认框中显示图像?我已经尝试了下面的代码,但是在提示框中只得到图像的URL。请有人帮我解决问题,或者提供其他建议如果这不可能。
var image = document.getElementById("myImage").src="hackanm.gif";
alert("OnLoad image"+image );
如何在提示框或确认框中显示图像?我已经尝试了下面的代码,但是在提示框中只得到图像的URL。请有人帮我解决问题,或者提供其他建议如果这不可能。
var image = document.getElementById("myImage").src="hackanm.gif";
alert("OnLoad image"+image );
JavaScript中的警告框只能显示纯文本。您可以使用像jQuery这样的JavaScript库来显示一个模态框代替吗?
这可能会有用:
http://jqueryui.com/dialog/您可以按照以下方式进行操作:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Dialog - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
body {
font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif";
font-size: 62.5%;
}
</script>
<script>
$(function() {
$( "#dialog" ).dialog();
});
</script>
</head>
<body>
<div id="dialog" title="Basic dialog">
<p>Image:</p>
<img src="http://placehold.it/50x50" alt="Placeholder Image" />
</div>
</body>
</html>
尖酸刻薄但可能有用的回答:http://picascii.com/(目前已经无法访问)
https://www.ascii-art-generator.org/es.html (别忘了在每行末尾加上 \n !)
正如其他人提到的那样,你不能在警报框中显示图像。解决方案是在网页上显示它。
如果我已经在调试器中暂停了我的网页,并且已经加载了一张图片,我可以显示它。没有必要使用jQuery;使用这个本地的14行Javascript代码,它可以从代码或调试器命令行中工作:
function show(img){
var _=document.getElementById('_');
if(!_){_=document.createElement('canvas');document.body.appendChild(_);}
_.id='_';
_.style.top=0;
_.style.left=0;
_.width=img.width;
_.height=img.height;
_.style.zIndex=9999;
_.style.position='absolute';
_.getContext('2d').drawImage(img,0,0);
}
使用方法:
show( myimage );
<html>
<head>
</head>
<body>
<div id="divid">
<img>
</div>
<body>
</html>
<script>
$(document).ready(function(){
$("btn").click(function(){
$("divid").dialog();
});
});
</script>
`
首先,您需要在页面中包含jQuery UI。
你可以使用表情符号!
$('#test').on('click', () => {
alert(' Build is too fast');
})
由于JS对话框只显示文本,您可以尝试使用表情符号。例如:
alert('Hello friend! \u{1F642}');
你只需要使用所需表情符号的 Unicode 十六进制值即可。 以下是可用表情符号的列表:https://unicode.org/emoji/charts/emoji-list.html
function alertImage(imgsrc) {
$('.d').css({
'position': 'absolute',
'top': '0',
'left': '50%',
'-webkit-transform': 'translate(-50%, 0)'
});
$('.d').animate({
opacity: 0
}, 0)
$('.d').animate({
opacity: 1,
top: "10px"
}, 250)
$('.d').append('An embedded page on this page says')
$('.d').append('<br><img src="' + imgsrc + '">')
$('.b').css({
'position':'absolute',
'-webkit-transform': 'translate(-100%, -100%)',
'top':'100%',
'left':'100%',
'display':'inline',
'background-color':'#598cbd',
'border-radius':'4px',
'color':'white',
'border':'none',
'width':'66',
'height':'33'
})
}
<script type="text/javascript" src="https://code.jquery.com/jquery-latest.min.js"></script>
<div class="d"><button onclick="$('.d').html('')" class="b">OK</button></div>
.d{
font-size: 17px;
font-family: sans-serif;
}
.b{
display: none;
}