【问题标题】:jquery modal dialog onclick?jquery模态对话框onclick?
【发布时间】:2011-01-22 02:54:57
【问题描述】:

我想要这个:

http://jqueryui.com/demos/dialog/#modal-message

点击 ClickMe 时发生。

如何做到这一点?

<script type="text/javascript">
$(document).ready(function() {
$('div.thedialog').dialog({ autoOpen: false })
$('#thelink').click(function(){ $('div.thedialog').dialog('open'); });
}
    </script>
</head>
<body>
<div id="thedialog" title="Download complete">
    <p>
        <span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
        Your files have downloaded successfully into the My Downloads folder.
    </p>
    <p>
        Currently using <b>36% of your storage space</b>.
    </p>
</div>
<a href="#" id="thelink">Clickme</a>

什么都没发生

【问题讨论】:

    标签: jquery dialog modal-dialog


    【解决方案1】:

    使用jQuery UI 对话框,在$(document).ready(...) 中执行:

    $('div.thedialog').dialog({ autoOpen: false })
    

    创建对话框和

    $('#thelink').click(function(){ $('div.thedialog').dialog('open'); });
    

    打开它。

    【讨论】:

    • 不起作用..我有这个:Clickme 然后文档中的这两行准备好了,然后是一个名为“ thedialog”,但它不会工作
    【解决方案2】:

    @Azzyh 我觉得@Rune 意味着你必须为它编写一个脚本。

    你把它放到你的html标签里

    <script src="script.js" type="text/javascript"></script> 
    

    (您还必须将 JQuery-ui 脚本和 JQuery 脚本链接到您的页面,如上所示(例如 &lt;script src="http://jquery-ui.googlecode.com/svn/tags/latest/ui/minified/jquery-ui.min.js" type="text/javascript"&gt;&lt;/script&gt;)

    其中 script.js 是脚本文件(与 html 文件位于同一文件夹中)。

    现在,在你编写的 script.js 中

    $(document).ready(function(){
       $('div.thedialog').dialog({ autoOpen: false })
       $('#thelink').click(function(){ $('div.thedialog').dialog('open'); });
    });
    

    PS:如果你想学习如何做你在互联网上看到的所有很酷的东西,请阅读this book。

    【讨论】:

      【解决方案3】:

      用div#thedialog 代替div.thedialog。 . 用于类名,# 用于处理 ids。

      (另外,如果这是您使用的实际代码,则缺少括号:))

      工作代码:

      <!doctype html>
      <head>
          <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.0/themes/ui-lightness/jquery-ui.css" />
          <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
          <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" type="text/javascript"></script>
          <script type="text/javascript">
      $(document).ready(function() {
      $('div#thedialog').dialog({ autoOpen: false })
      $('#thelink').click(function(){ $('div#thedialog').dialog('open'); });
      })
          </script>
      </head>
      <body>
      <div id="thedialog" title="Download complete">
          <p>
              <span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
              Your files have downloaded successfully into the My Downloads folder.
          </p>
          <p>
              Currently using <b>36% of your storage space</b>.
          </p>
      </div>
      <a href="#" id="thelink">Clickme</a>
      </body>
      

      【讨论】:

      • +1 只是不要忘记包含样式表,它看起来更好:)
      猜你喜欢
      • 1970-01-01
      • 2015-05-15
      • 1970-01-01
      • 1970-01-01
      • 2013-02-27
      • 2013-03-13
      • 2011-04-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多