繁体   English   中英

在jQuery中设置对话框文本

[英]Set the dialog box text in jquery

我是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>

GetDetail函数

public String GetDetails1()
{
    List<User> imagelist = DatabaseAccessor.getImagesFromDataBase();
    return imagelist[Convert.ToInt32(JavascriptValue.Value)].Detail;
}

我认为您的问题在于这些行document.forms['form1'].JavascriptValue.value 您需要像document.getElementById("JavascriptValue").value 您的隐藏字段默认设置为1,这就是为什么总是获取第一张图片的详细信息的原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM