使用asp.net c#不会出现模态弹出窗口

时间:2016-09-27 06:53:51

标签: javascript c# jquery asp.net

使用asp.net C#没有出现模态弹出窗口并且有一个示例,但该示例无法使用asp.net C#网络表单。

以下是我的设计代码。

<style type="text/css">

body { font: normal normal normal 10px/1.5 Arial, Helvetica, sans-serif;    }

 .ui-dialog-osx {
-moz-border-radius: 0 0 8px 8px;
-webkit-border-radius: 0 0 8px 8px;
border-radius: 0 0 8px 8px; border-width: 0 8px 8px 8px;
}
</style>
<link href="jquery-ui.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">

$("#dialog-message").dialog({
    modal: true,
    draggable: false,
    resizable: false,
    position: ['center', 'top'],
    show: 'blind',
    hide: 'blind',
    width: 400,
    dialogClass: 'ui-dialog-osx',
    buttons: {
        "I've read and understand this": function () {
            $(this).dialog("close");
        }
    }
});


setInterval(function () {
    $('#dialog-message').dialog('open');
    setTimeout(function () {
        $('#dialog-message').dialog('close');
    }, 1000)
}, 2000);

</script>

以下是我的身体设计代码。

<body>
<form id="form1" runat="server">
<div>
    <p>
        Hello World!
    </p>
    <div id="dialog-message" title="Important information">
        <span class="ui-state-default"><span class="ui-icon ui-icon-info" style="float: left;
            margin: 0 7px 0 0;"></span></span>
        <div style="margin-left: 23px;">
            <p>
                We're closed during the winter holiday from 21st of December, 2010 until 10th of
                January 2011.
                <br />
                <br />
                Our hotel will reopen at 11th of January 2011.<br />
                <br />
                Another line which demonstrates the auto height adjustment of the dialog component.
            </p>
        </div>
    </div>
</div>
</form>
</body>

我正在尝试工作小提琴:http://jsfiddle.net/92jv0erw/但弹出窗口不显示正文中显示的文字。

1 个答案:

答案 0 :(得分:0)

继续发表评论和聊天后,最初发布的代码中存在一些问题:

1)原始代码中没有对jQuery或jQuery UI的引用。需要包含对这些脚本的引用。

2)尝试设置对话框的JS代码在它引用的HTML元素存在之前运行 - 因为脚本位于页面上方,脚本在元素实际存在于浏览器之前执行,导致它失败了。 最简单的解决方案是将脚本移动到HTML标记下方。因此,您应该将<script type="text/javascript">块及其所有内容移动到页面底部。 </form></body>结束标记之间的合理位置。