$('#dlg')。dialog('close')不适用于简单的JSP页面

时间:2019-03-29 11:08:24

标签: jquery jsp jquery-easyui

$('#dlg').dialog('close')不可点击,在“保存”按钮上将发出警报。关于StackOverflow的答案与iframe有关。就我而言,它不起作用。

<div id="dlg" class="easyui-dialog" title="Complex Toolbar on Dialog" style="width: 400px; height: 200px; padding: 10px" data-options="iconCls: 'icon-save', buttons: '#dlg-buttons'">
  The dialog content.
</div>
<div id="dlg-buttons">
  <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:alert('save')">Save</a>
  <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#dlg').dialog('close')">Close</a>
</div>

单击关闭时,对话框窗口应该会关闭。

1 个答案:

答案 0 :(得分:0)

如果您检查控制台,则应该出现一些错误,例如“ 在初始化之前无法在对话框上调用方法;​​尝试调用方法'close'

简单的解决方法是:

$('#dlg').dialog().dialog('close');

演示:

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<div id="dlg" class="easyui-dialog" title="Complex Toolbar on Dialog" style="width: 400px; height: 200px; padding: 10px" data-options="iconCls: 'icon-save', buttons: '#dlg-buttons'">
  The dialog content.
</div>
<div id="dlg-buttons">
  <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:alert('save')">Save</a>
  <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#dlg').dialog().dialog('close');">Close</a>
</div>