【发布时间】:2016-05-11 21:06:12
【问题描述】:
在将 html 替换为我自己的 html 之前,将想法 here 用作“概念验证”,我将改编自该 html 的 html 添加到我的 Index.cshtml 文件(ASP.NET MVC 应用程序)中:
<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;">
<label>
Add additional Email:
</label>
<input type="text" id="addlemail" />
<button id="btnSaveAddlEmail">
Save
</button>
</div>
</div>
...以及该文件的脚本部分中的此 jQuery 以打开该 div(单击处理程序中先前的普通警告已被注释掉):
$('#dialog-message').dialog({
autoOpen: false,
modal: true,
draggable: false,
resizable: false,
position: ['center', 'top'],
show: 'blind',
hide: 'blind',
width: 400,
dialogClass: 'ui-dialog-osx'
});
$("#btnAddlEmail").click(function () {
//var email = prompt('Please enter the email address', 'name@provider.com');
//if (null != email) //&& (email != "name@provider.com")
//{
// alert(email);
//}
$('#dialog-message').dialog('open');
}); // $("#btnAddlEmail").click(function ()
但是,当我单击“+ 添加另一封电子邮件”时,“对话框”仅显示在页面底部,而不是模式对话框中:
(我也不知道“关闭”按钮是从哪里发出的)。
注意:按照here 所讨论的here 中的步骤,我已经(大概无论如何)完成了使jQuery UI 在我的项目中工作所必需的工作。
为了让对话框充当模态对话框而不是日志文件上的凹凸,我必须跳过什么环?
更新
我在 \Home\Index.cshtml 文件中添加了以下脚本引用:
@section Scripts
{
<script type="text/javascript">
【问题讨论】:
-
您显示的代码工作正常(参考this fiddle)。如果你没有得到对话框,那么你没有包含 jquery-ui 的相关脚本和/或 css 文件。
-
我想我不知道在哪里添加它们;我尝试将它们直接添加到 .cshtml 文件的 Scripts 部分下方,但没有奏效。
-
您需要编辑您的问题以显示您加载脚本和 css 文件的位置。
-
您的编辑并未显示您正在加载任何脚本。在您的
@section Scripts {中,您需要包含jquery-{version}.js和jquery-ui.js,然后您还需要包含相关的css 文件。
标签: jquery html asp.net-mvc jquery-ui jquery-ui-dialog