简体   繁体   English

对话框不显示

[英]Dialog doesn't show

I thought I've done everything correctly but my dialog in Rails app doesn't show when I click on link. 我以为我已正确完成了所有操作,但单击链接后我的Rails应用程序对话框没有显示。

This is the code for link: 这是链接的代码:

<li><%= link_to "Sign in", :class => "userlink" %></li>

This is my dialog: 这是我的对话框:

<div id="loginf"  style="display:none;">
    <div class="col-md-3">
        <%= form_for(:session, url: sessions_path) do |f| %>

        <%= f.label :username %>
        <%= f.text_field :username %>

        <%= f.label :password %>
        <%= f.password_field :password %>

        <%= f.submit "Sign in", class: "btn" %>
        <% end %>

        <p>New user? <%= link_to "Sign up now!", signup_path %></p>
    </div>
</div>

And this is my javascript stored inside assets/javascripts/dialog : 这是我存储在assets/javascripts/dialog

$(document).ready(function(){

    $("a.userlink").click(function(e) {
        $("#loginf").dialog("open");
        e.preventDefault();
        return false;
    });

    $("#loginf").dialog({
        autoOpen: false,
        modal: true,
        resizable: false,
        draggable: false
    });
});

Everything seems fine to me. 在我看来一切都很好。 When I remove style="display:none;" 当我删除style="display:none;" , div normally appears and looks ok. div通常会出现,并且看起来不错。 Also, if I set alert box inside javascript click function, that alert box normally displays. 另外,如果我在javascript click函数中设置了alert框,则通常会显示该警告框。

What do you think? 你怎么看?

you can try this 你可以试试这个

$("#model").click(function(){
   $( "#dialog-modal" ).dialog({
     height: 140,
     modal: true
   });
});

DEMO 演示

I think you should remove "display:none" style from div, because you'r already using autoOpen:false option . 我认为您应该从div中删除“ display:none”样式,因为您已经在使用autoOpen:false选项。

Please refer to this link for more details: http://api.jqueryui.com/dialog/#option-autoOpen 请参考此链接以获取更多详细信息: http : //api.jqueryui.com/dialog/#option-autoOpen

autoOpenType: Boolean

Default: true
If set to true, the dialog will automatically open upon initialization. If false, the      dialog will stay hidden until the open() method is called.
Code examples:
Initialize the dialog with the autoOpen option specified:

$( ".selector" ).dialog({ autoOpen: false });
Get or set the autoOpen option, after initialization:

// getter
var autoOpen = $( ".selector" ).dialog( "option", "autoOpen" );

// setter
$( ".selector" ).dialog( "option", "autoOpen", false );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM