Bootstrap模式之上的jQuery UI对话框

时间:2015-08-04 08:43:31

标签: css twitter-bootstrap jquery-ui bootstrap-modal

我有一个Bootstrap模式,显示填充一些数据,如果数据不正确,实际上我显示一个警报,它显示在顶部。

现在我有了新的要求,创建自定义警报对话框。在表单的其他部分,没有问题,但是当我有Bootstrap模式时,如果我以正常方式显示模态,它会出现在Bootstrap模式(example in this fiddle)的底部。

我已经查看了其他问题,例如thisthis,我已尝试使用z-indexexample in this fiddle)和对话框显示在顶部,但是我无法点击任何地方

$(".ui-dialog").css({ 'z-index' : 1000 });    
$("#myModal").css({ 'z-index' : 0 });

此外,我已尝试禁用模式并启用对话框但未成功。

this answer是否正确,如果没有更多插件,我无法实现这一目标?

3 个答案:

答案 0 :(得分:2)

variables.less 文件中定义的引导模式窗口的默认z-index位于1050

  

@ zindex-modal:1050;

因此,如果您想将jquery-ui对话框放在上面,那么至少需要添加一个大于模态窗口的z-index值。或者将模态窗口z-index更改为更低的值,但我不会这样做。

$("#btnalert").click(
  function action () {
    alert("this is an alert on top");
  }
);

$("#btndialog").click(
  function action () {
    $("#dialog").html("dialog on the back");
    $("#dialog").dialog();
    $(".ui-dialog").css({
      zIndex: '1060',
      top: '100px'
    });
    prepareDialog();
    
  }
);

function prepareDialog() {
  $("html, body").animate({ scrollTop: 0 }, "slow");
  $(".ui-dialog-titlebar").css({ background: '#F7985D' });
  $(".ui-dialog .ui-dialog-content").css({ 'text-align': 'center' });
}
.ui-dialog {
    /*z-index: 1060 !important;*/
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://code.jquery.com/ui/1.11.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>



<!-- Latest compiled JavaScript -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>


<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        <p>Some text in the modal.</p>
      </div>
      <div class="modal-footer">
        <button  class="btn btn-default" id="btnalert" >ALERT</button>
        <button  class="btn btn-default" id="btndialog" >DIALOG</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>

<div id="dialog" hidden></div>

答案 1 :(得分:0)

版本1.10.0 + 起,您可以在初始化中使用appendTo选项指定将对话框“附加”到何处并为其分配模式ID。 z索引不再更改。

$("#yourDialogId").dialog({
        autoOpen: false,
        appendTo: "#yourModalId",
        modal: true,
});

答案 2 :(得分:-2)

在你的小提琴上试试这个:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_height="wrap_content"
    android:paddingLeft="10dp" android:paddingRight="10dp"
    android:background="#10ffffff" android:layout_width="300dp"
    android:paddingTop="10dp">

    <TextView
        android:id="@+id/DialogDescription"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text=""
        android:layout_marginBottom="10dp"
        android:textColor="#ff8e8e90"
        android:textStyle="bold"/>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff5f5f5">

    <EditText android:layout_height="wrap_content"
        android:id="@+id/txtUsername"
        android:layout_width="match_parent"
        android:paddingLeft="30dp"
        >
        <requestFocus></requestFocus>
    </EditText>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxHeight="5dp"
            android:maxWidth="5dp"
            android:minHeight="5dp"
            android:minWidth="5dp"
            android:layout_gravity="left|center_vertical|center_horizontal"
            android:background="@drawable/ic_action_remove"
            android:id="@+id/DeleteTextUserName"
            android:layout_marginLeft="5dp"/>

    </FrameLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff5f5f5">

    <EditText android:layout_height="wrap_content"
        android:id="@+id/txtPassword"
        android:layout_width="match_parent"
        android:paddingLeft="30dp"
        >

    </EditText>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxHeight="5dp"
            android:maxWidth="5dp"
            android:minHeight="5dp"
            android:minWidth="5dp"
            android:layout_gravity="left|center_vertical"
            android:background="@drawable/ic_action_remove"
            android:id="@+id/DeleteTextPass"
            android:layout_marginLeft="5dp"/>

    </FrameLayout>
  <LinearLayout android:layout_width="match_parent"
        android:layout_height="wrap_content" android:id="@+id/linearLayout1">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:id="@+id/btnLogin"
            android:layout_marginTop="20dp"
            android:layout_marginBottom="10dp"
            android:text="Login"
            >
        </Button>

    </LinearLayout>
</LinearLayout>
相关问题