使用jQuery UI:如何将图像添加到对话框?

时间:2013-09-11 21:46:34

标签: javascript jquery html popupwindow

我正在使用jQuery UI,我想在对话框中添加一个图标。 对话框工作正常,但我想添加一张图片更具吸引力。我将不胜感激。

代码:

<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Dialog - Modal message</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>
<!--<link rel="stylesheet" href="/resources/demos/style.css" />!-->

<script>
$(function() {
$( "#dialog-message" ).dialog({
modal: true,
buttons: {
Ok: function() {
$( this ).dialog( "close" );
}
}
});
});
</script>
</head>
<body>
<div id="dialog-message" title="Download complete">
<p>
<!--<span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 50px 0;"></span>!-->
<span style ="float: left; margin:0 7px 50px 0; width:50px; height:37px;"><img src = "img1.jpg"></span>
Your files have downloaded successfully into the My Downloads folder.
</p>
<p>
Currently using <b>36% of your storage space</b>.
</p>
</div>
<p>Sed vel diam id libero <a href="http://example.com">rutrum convallis</a>. Donec aliquet leo vel magna. Phasellus rhoncus faucibus ante. Etiam bibendum, enim faucibus aliquet rhoncus, arcu felis ultricies neque, sit amet auctor elit eros a lectus.</p>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

将任何内容放入对话框中没有什么特别之处;它只是一个普通的HTML DIV。

问题是您没有为图片使用正确的HTML。改变这一行:

<span img src = "img1.jpg" style ="float: left; margin:0 7px 50px 0; width:50px; height:50px;"></span>

为:

<span style ="float: left; margin:0 7px 50px 0; width:50px; height:50px;"><img src = "img1.jpg"></span>

img不是<span>的属性,它是自己的元素。

答案 1 :(得分:0)

jQueryUI的dialog()所做的就是(1)在document.ready上隐藏指定的div,然后(2)在.dialog('open')方法(或只是对话框({/)时用一些奇特的css格式显示它/ options go here})方法)被调用。

因此,如果您的div包含没有实例化jQUI对话框的图像,那么它将包含使用jQUI对话框方法之后的图像。

您的问题可能是语法错误,您缺少<span>元素的结束尖括号以及<img>元素的左右括号。此外,您希望<span>元素所需的属性似乎附加到输入元素。

删除你的内嵌CSS(为简单起见),这将有效:

<span><img src = "img1.jpg"></span>