javascript - 模态形式消失而不点击形式

标签 javascript jquery html forms twitter-bootstrap

我们有一个可以正常工作并通过正确提交的表单。当我将表单转换为模态( Bootstrap )时出现问题。当表单呈现时,用户可以通过 Tab 键浏览并键入。选择框可以工作,可以按键盘上的回车键;但是,当我使用鼠标并单击模态上的任何元素(包括背景)时,它就会消失。请帮忙。这是代码:

    $('#new_event').click( function() {
      $('#all-events').toggle(false);
      $('#all-invitations').toggle(false);
      $('#friend-requests').toggle(false);
      $('#feed').toggle(false);
      $('#time-select-start').toggle(false);
      $('#time-select-end').toggle(false);
      $('#event-type-select').toggle(false);
      $('#event_location').val('Current Location');
      $('#event_location').attr('readonly',true);
      $('#new-event').toggle();
      check_dashboard();
    });

View :

%a{'href' => '#new-event','data-toggle' => 'modal', 'class' => 'btn btn-primary btn-small'}
      new event
:
:
#new-event{'class' => 'modal hide fade'}
      = render 'events/new_event'

这是表格:

.modal-form
.fieldset
    .container
        %center
            .well.span6{:style => "position:relative; right:2.1%;background-color:#ffffff;"}

                %h1{:style => 'font-family:eight_one;font-weight:normal;color:#ff6699;'} quick rondé 
                = form_for(@event, html: { class: 'form-vertical' }) do |f|
                    %div
                        = f.text_field :name,:autofocus => 'true',:placeholder => "event name"
                    %div
                        = f.text_area :description, rows: 3, :placeholder => "give your friends some more details and convince them to come "
                    %div
                        = f.text_field :location,:placeholder => "location"
                    %div
                        = f.text_field :event_type, :placeholder => 'event type'
                    %ul.span3.dropdown-menu#event-select-type{:style => 'position:absolute; left:27.65%;top:63%;',"role" => "menu"}
                        %li
                            %a#Food{:href => '#'} food
                            %a#Drink{:href => '#'} drink
                            %a#Other{:href => '#'} other

                    %div
                        = f.text_field :start, :placeholder => 'start time'
                    %ul.span3.dropdown-menu#time-select-start{:style => 'position:absolute; left:27.65%;top:73%;',"role" => "menu"}
                        %li#time-list-start
                    %div
                        = f.text_field :end, :placeholder => 'end time'
                    %ul.span3.dropdown-menu#time-select-end{:style => 'position:absolute; left:27.65%;top:82%;',"role" => "menu"}
                        %li#time-list-end
                    %a{'data-dismiss' => 'modal'} Cancel        
                    = f.submit value: 'Create', class: 'btn btn-info' 

任何帮助都会很棒。我是 javascript、haml 和模态的新手...谢谢。

最佳答案

您是否尝试过阻止表单上的默认操作?

    $(document).bind("modal-form",function(e){
     return false;
    });

还是处理鼠标事件?

    $(".modal-form").mouseup(function(e){
      switch(e.which){
        case 1:
          left click event;
        break;
        case 2:
          middle click event;
        break;
        case 3:
          right click event;
        break;
        default:
          default action;
       }
      });

关于javascript - 模态形式消失而不点击形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20297356/

相关文章:

javascript - 弹出 div 在浏览器调整大小时收缩

javascript - 背景图像 - 改变

javascript - 在滚动位置更改文本内容

javascript - 在控制台中使用新脚本重新加载页面

javascript - 在示例中将 promise 与 Node.js 函数结合使用

jquery - 无法在 "beforeunload"事件中设置背景图像属性

php - 使用 jQuery 向 PHP 发送 PUT AJAX 请求时出现错误 405 方法不允许

javascript - Swiper.js - 未捕获的类型错误 : Cannot read property 'params' of null

javascript - 道场验证

javascript - 查询/CSS : Full size background image