jquery ui 对话框无法打开

发布于 2024-11-02 11:33:05 字数 749 浏览 0 评论 0原文

我试图在用户单击锚链接后打开 Jquery UI 对话框。

我正在使用 Jquery 1.5.2 和 UI 1.8.11,并且没有收到任何错误消息。我正在遵循此页面上的示例: jquery ui 对话框文档

我的 JS:

$(document).ready(function() {
  $('#payTypeOptions').dialog({
    autoOpen: false,
    height:600,
    width: 600,
    modal: true
});

  $('#showPayTypeOptions').click(function(){
    $('#payTypeOptions').dialog('open');
    //If I put an alert() here, the alert shows
  });

});

HTML :

<a id="showPayTypeOptions">Do something</a>

<div id="payTypeOptions">
 <p>Content</p>
</div>

谢谢。

编辑:代码没有任何问题。这是导入过程中的用户错误 - doh!

I'm trying to open a Jquery UI dialog box after the user clicks on an anchor link.

I'm using Jquery 1.5.2 and UI 1.8.11 and am getting no error messages. I am following the example on this page: jquery ui dialog documentation

My JS:

$(document).ready(function() {
  $('#payTypeOptions').dialog({
    autoOpen: false,
    height:600,
    width: 600,
    modal: true
});

  $('#showPayTypeOptions').click(function(){
    $('#payTypeOptions').dialog('open');
    //If I put an alert() here, the alert shows
  });

});

The HTML:

<a id="showPayTypeOptions">Do something</a>

<div id="payTypeOptions">
 <p>Content</p>
</div>

Thanks.

Edit: There was nothing wrong with the code. It was user error in the import process - doh!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

猫弦 2024-11-09 11:33:05

我以前也遇到过这种情况,这与进口有关。
要查看是否是这种情况,请尝试以下脚本和样式。
尝试:

<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/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>

I've had this happen to me before too and it had to do with the imports.
To see if that's the case, try the following scripts and styles.
try:

<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/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>
七分※倦醒 2024-11-09 11:33:05

试试这个:

$(document).ready(function() {
    $('#showPayTypeOptions').click(function(){

        $('#payTypeOptions').dialog({
            autoOpen: false,
            height:600,
            width: 600,
            modal: true
        });
    });
});

看看是否会打开模式。如果是这样,那么您需要先声明模态块,然后再尝试打开它。

Try this:

$(document).ready(function() {
    $('#showPayTypeOptions').click(function(){

        $('#payTypeOptions').dialog({
            autoOpen: false,
            height:600,
            width: 600,
            modal: true
        });
    });
});

See if that opens the modal. If it does then you'll need to declare the modal piece first before you try to open it.

花开柳相依 2024-11-09 11:33:05
$(document).ready(function() {
    $('#payTypeOptions').dialog({
        autoOpen: false,
        height:600,
        width: 600,
        modal: true
    });

    $('#showPayTypeOptions').click(function(){
        $('#payTypeOptions').dialog('open');
        //If I put an alert() here, the alert shows
    });
});

我认为,您必须交换它们,首先创建对话框,然后调用它。

$(document).ready(function() {
    $('#payTypeOptions').dialog({
        autoOpen: false,
        height:600,
        width: 600,
        modal: true
    });

    $('#showPayTypeOptions').click(function(){
        $('#payTypeOptions').dialog('open');
        //If I put an alert() here, the alert shows
    });
});

You have to swap them around, I think, where you're creating the dialog box first, then calling it up.

身边 2024-11-09 11:33:05

创建像这里这样的函数 http://pluksza.blogspot .com/2011/06/jquery-ui-dialog-open-good-practise.html 并将事件绑定到按钮

Create function like here http://pluksza.blogspot.com/2011/06/jquery-ui-dialog-open-good-practise.html and bind event to button

彩虹直至黑白 2024-11-09 11:33:05

我遇到了非常相似的问题,但我的模式打开了一瞬间,然后就消失了。当我单击“打开对话框”按钮时,我通过观察 Chrome 开发工具 Elements 选项卡中的 HTML 变化来找到解决方案。您必须记住,如果单击的元素是按钮或链接,则返回 false,否则您的页面将再次发布或获取,并且您会丢失对话框。所以我的代码看起来像这样:

$(document).ready(function() {

  $('#payTypeOptions').dialog({
    autoOpen: false,
    height: 600,
    width: 600,
    modal: true
  });

  $('#showPayTypeOptions').click(function() {
    $('#payTypeOptions').dialog('open');
    return false; // This makes all the difference in my case
  });

});

希望这对某人有帮助

I had a very similar problem but my modal opened for a split second and then disappeared. I worked out the solution by watching the HTML change in the Chrome dev tool Elements tab as I clicked on my "open the dialog" button. You have to remember to return false from the clicked element, if it's a button or link, otherwise your page will be posted or get'ed again and you lose your dialog. So my code would look something like:

$(document).ready(function() {

  $('#payTypeOptions').dialog({
    autoOpen: false,
    height: 600,
    width: 600,
    modal: true
  });

  $('#showPayTypeOptions').click(function() {
    $('#payTypeOptions').dialog('open');
    return false; // This makes all the difference in my case
  });

});

Hope this helps someone

心不设防 2024-11-09 11:33:05

尝试将对话框存储在变量中并引用它。我已经成功地这样做了:

$(document).ready(function() {
  var mydialog = $('#payTypeOptions').dialog({
    autoOpen: false,
    height:600,
    width: 600,
    modal: true
  });

  $('#showPayTypeOptions').click(function(){
    mydialog.dialog('open'); //Changed here
    //If I put an alert() here, the alert shows
    //Also, you should probably return false here to prevent the browser
    // from following the link (or doing something weird since you don't have
    // an href).
    return false;
  });

});

Try storing the dialog in a variable and referencing that. I've had success doing it this way:

$(document).ready(function() {
  var mydialog = $('#payTypeOptions').dialog({
    autoOpen: false,
    height:600,
    width: 600,
    modal: true
  });

  $('#showPayTypeOptions').click(function(){
    mydialog.dialog('open'); //Changed here
    //If I put an alert() here, the alert shows
    //Also, you should probably return false here to prevent the browser
    // from following the link (or doing something weird since you don't have
    // an href).
    return false;
  });

});
忱杏 2024-11-09 11:33:05

一旦你声明了对话框(在“打开”之前),你可以使用 DOM 检查器(firebug)来检查 div 吗?声明对话框后,您应该会看到 jQuery 创建的许多附加标记。 ui-widget、ui-dialog 等...

Once you declare the dialog (before you 'open') can you use a DOM inspector (firebug) to review the div? Once the dialog is declared you should see a lot of additional markup created by jQuery. ui-widget, ui-dialog, etc...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文