我是 jquery 的新手,我遇到了一个问题。我正在尝试设计一个包含四个图像的网页,并且我希望弹出一个对话框,显示被单击的当前图像的详细信息。但是,我无法更改对话框中的文本,并且它始终显示第一张图像的详细信息。
在隐藏字段中设置一个数字以标识单击了哪个图像,然后 GetDetail1() 和 GetDetail2() 函数使用该数字返回具有适当详细信息的字符串。继承人的脚本:
<asp:HiddenField runat="server" Id="JavascriptValue" value="1"/>
<div id="dialog-block">
<b>Detail1:</b>
<table border="0">
<tr>
<td><% =GetDetail1() %></td>
<td colspan="2">
<img src="Assets\people\silhoeutte1.jpg" width="100" height="100" style="padding-left: 100px;" /></td>
</tr>
<tr>
<td><b>Detail2:</b></td>
</tr>
<tr>
<td><% =GetDetail2() %></td>
</tr>
</table>
</div>
<script type="text/javascript">
// the jQuery document ready handler
$(function () {
var name;
// create our dialog
$('#dialog-block').dialog({
title: '<%=GetImageName()%>',
oneInstance: false,
autoOpen: false,
width: 400,
buttons: {
"Close": function () {
closeDialog($(this))
}
}
});
// the images to open the dialog
$('#image1,#image3,#image2,#image4').click(function (event) {
if (this.id == 'image1') {
document.forms['form1'].JavascriptValue.value = "1"; //set the value
$('#dialog-block').dialog('open');
}
else if (this.id == 'image2') {
document.forms['form1'].JavascriptValue.value = "2"; //set the value
$('#dialog-block').dialog('open');
}
else if (this.id == 'image3') {
document.forms['form1'].JavascriptValue.value = "3";//set the value
$('#dialog-block').dialog('open');
}
else if (this.id == 'image4') {
document.forms['form1'].JavascriptValue.value = "4"; //set the value
$('#dialog-block').dialog('open');
}
});
});
function closeDialog(elem) {
elem.dialog("close");
}
</script>
获取详细信息函数
public String GetDetails1()
{
List<User> imagelist = DatabaseAccessor.getImagesFromDataBase();
return imagelist[Convert.ToInt32(JavascriptValue.Value)].Detail;
}