javascript - Jquery 模式无法正常工作

标签 javascript jquery jquery-ui jquery-ui-dialog

我正在尝试使用 jquery ui 模式,但它不能满足我的需要,即,我想仅在模式内部显示数据,但在这里它在我单击按钮之前显示。

function pop_up()
{
var dialog, form
        dialog = $('div#infoDialog').dialog({
          autoOpen: false,
          height: 600,
          width: 500,
          modal: true
        });
        $('#showInfos').click(function(e){
          e.preventDefault();
          dialog.dialog('open');
        });
}
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/redmond/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

    <button type="button" id="showInfos" onclick="pop_up();">test</button>
    <div id="infoDialog" title="Eventinfos">
      <p>
        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum
      </p>
    </div>

最佳答案

您的代码几乎是正确的,您的代码中只有一个错误,那就是您将所有 javascript 代码与 onclick 事件绑定(bind)在一起,这就是它默认显示模式内容的原因。 所以现在你只需删除 onclick 事件和 pop_up() 函数即可。所以你的最终代码将如下所示。

<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
 
<script src="https://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>

<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css" />

    <button type="button" id="showInfos" >test</button>
    <div id="infoDialog" title="Eventinfos">
      <p>
        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum
        
      </p>
    </div>

    <script>
   // function pop_up()
  // {
  var dialog, form
          dialog = $('div#infoDialog').dialog({
            autoOpen: false,
            height: 600,
            width: 500,
            modal: true
          });
          $('#showInfos').click(function(e){
            e.preventDefault();
            dialog.dialog('open');
          });
  // }
    </script>

关于javascript - Jquery 模式无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48739562/

相关文章:

javascript - 处理 'incorrect string values'

jquery - onclick 清除 dropzone 文件字段

javascript - 创建 jquery 插件的更好方法

javascript - Jquery UI Datepicker altField 输入不起作用

javascript - 操作系统暂停时恢复 Android webview/在后台应用程序上运行 JavaScript?

javascript - 获取 webpack bundle 中包含的主要库/模块的版本

javascript - 使用jquery动态加载js

php - 有没有好的支持ajax搜索、过滤的treeview控件?

jquery - 如何根据鼠标位置和 jQuery UI Draggable 向 html 文档添加控件?

javascript - 为丢失的变量创建计数器