5

我试图让一个 jquery 对话框在单击按钮时启动,但似乎没有工作。任何帮助,将不胜感激:

    $('#wrapper').dialog({
        autoOpen: false,
        title: 'Basic Dialog'
    });
    $('#opener').click(function() {
        $(this).dialog('open');
        return false;
    });
    
    
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>
<button id="opener">Open the dialog</button>
    <div id="wrapper">
    <p>Some txt goes here</p>
    </div>

谢谢!

4

3 回答 3

8

这条线

$(this).dialog('open');  // this here corresponds to the #opener div

应该是

$('#wrapper').dialog('open');

还有额外的大括号.. 如果这是DOM Ready 处理程序}); 的右大括号,则可以忽略

检查小提琴

于 2012-11-27T20:27:09.537 回答
3

确保您引用了 jQuery 和 jQueryUI 库,如下面的示例所示。

尝试这个:

<html>
    <head>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>
        <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" media="all" />

        <script type="text/javascript">
            $(document).ready(function() {

                $('#wrapper').dialog({
                    autoOpen: false,
                    title: 'Basic Dialog'
                });
                $('#opener').click(function() {
                    $('#wrapper').dialog('open');
//                  return false;
                });
            });
        </script>
    </head>
<body>

<button id="opener">Open the dialog</button>
<div id="wrapper">
    <p>Some txt goes here</p>
</div>
于 2012-11-27T20:31:04.317 回答
1

试试这个代码,它对我有用。

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Dialog - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="https://jqueryui.com/resources/demos/style.css">
<script>
$(document).ready(function() {
  $(function() {
    console.log('false');
    $( "#dialog" ).dialog({
        autoOpen: false,
        title: 'Test'
    });
  });

  $("button").click(function(){
    console.log("click");
        $(this).hide();
        $( "#dialog" ).dialog('open');
    });
}); 
</script>
</head>
<body>
<button id="open">Open Dialog box</button> 
<div id="dialog" title="Basic dialog">
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
</body>
</html>
于 2016-04-02T10:04:17.320 回答