c# - jquery模态对话框打开带有多个图像的图像onclick

标签 c# jquery css asp.net modal-dialog

有许多缩略图,我希望模式对话框以全尺寸图像 onclick 打开。我想将全尺寸图像的 'src' 动态传递给 'dialog' div 'src'

C#代码:

        <div id="dialog" title="American Lady Caterpillar">
            <img id="myImage" src="../Images/Caterpillar/Cat_AmericanLady.jpg" style="vertical-align: top; padding: 0px 10px 10px 2px;" />
        </div>


        <table id="cat_tbl">
            <tr>
                <td class="cat_colwidth">
                    <img class="imgLink" src="../Images/Caterpillar/Cat_AmericanLady_Thumb.jpg" style="float:left; padding: 0px 10px 10px 2px;" />
                    <span class="cat_bold">Genus</span>:  Vanessa &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <span class="cat_bold">Species</span>: virginiensis <br />
                    <span class="cat_bold">Common Name: American Lady<br />
                    <span class="cat_bold">Group</span>:</span> Brushfoots<br />
                    <span class="cat_bold">Host Plants</span>: Sweet everlasting, Pearly everlasting, Plantain-leaved pussy toes, and Ironweed 
                </td>
            </tr>
            <tr>
                <td class="cat_colwidth">
                    <img class="imgLink"  src="../Images/Caterpillar/Cat_Viceroy_Thumb.jpg" style="float:left; padding: 0px 10px 10px 2px;" />
                    <span class="cat_bold">Genus</span>:  Limenitis &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <span class="cat_bold">Species</span>: archippus<br />
                    <span class="cat_bold">Common Name</span>:<br />
                    <span class="cat_bold">Group</span>: Admirals<br />
                    <span class="cat_bold">Host Plants</span>: Trees in the willow family including Willows, and Poplars and Cottonwoods
                </td>
            </tr>
</table>

Jquery——到目前为止:

<script>
    $(document).ready(function() {
        $('#dialog').dialog({ autoOpen: false })
        $('.ui-dialog').css({
            width  : 600,
            height: 450})
        $('.imgLink').click(function () {
            $('#myImage').attr('src', imgSrc);
            $('#dialog').dialog('open').css({
                width: 600,
                height: 450
            });
        });
    });
</script>

最佳答案

如果你的代码只是这样,问题就在这里:

$('#myImage').attr('src', imgSrc);

更改为:

$('#myImage').attr('src', $(this).attr('src').replace('_Thumb', ''));

关于c# - jquery模态对话框打开带有多个图像的图像onclick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42078174/

相关文章:

c# - 使用 ServiceStack.Text 序列化 ExpandoObject

asp.net-mvc - 查询字符串中的 RequestVerificationToken

html - 我应该在 <li> 或 <ul> 上定义列表样式吗?

c# - 使用 Ajax.BeginForm 发布数据时的空模型

c# - 如何在数据库中找不到记录时将新项目添加到下拉列表

jquery - 使用 jQuery/Javascript 保留 Django 中显示/隐藏部分的状态

html - 响应式固定边栏 CSS

css - pdf 2 xhtml/css

c# - 如何在不使用系统命名空间的情况下使用字符串

javascript - 为什么我必须点击两次才能打开和关闭我的菜单