从引导下拉菜单触发模式

时间:2019-06-28 11:08:16

标签: javascript twitter-bootstrap bootstrap-modal

我有一个bootstrap下拉菜单,其中的链接打开了一个模态。一切似乎在台式机上都可以正常运行,但模式无法在移动设备上打开。我在同一页面上有一个按钮,可以再次打开模式,这些模式可以正常工作。手机只是一个问题(在iPhone上试用过)。

<!-- Dropdown code -->
<div class="dropdown">
    <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">Choose Product <span class="caret"></span></button>
        <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
            <li><a href="#" data-toggle="modal" data-target="#modal1">Open modal 1</a></li>
            <li><a href="#" data-toggle="modal" data-target="#modal2">Open modal 2</a></li>
        <ul>
<div>

<!--Modal code -->
<div class="modal fade" id="modal1" tabindex="-1" role="dialog" aria-labelledby="modal1-label">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h2 class="modal-title">Modal 1</h2>
            </div>
        </div>
    </div>
</div>

任何帮助表示赞赏。谢谢

3 个答案:

答案 0 :(得分:0)

您尚未关闭divul标签

<!-- Dropdown code -->
<div class="dropdown">
  <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">Choose Product <span class="caret"></span></button>
  <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
    <li><a href="#" data-toggle="modal" data-target="#modal1">Open modal 1</a></li>
    <li><a href="#" data-toggle="modal" data-target="#modal2">Open modal 2</a></li>
  </ul>
</div>

<!--Modal code -->
<div class="modal fade" id="modal1" tabindex="-1" role="dialog" aria-labelledby="modal1-label">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h2 class="modal-title">Modal 1</h2>
      </div>
    </div>
  </div>
</div>
<div class="modal fade" id="modal2" tabindex="-1" role="dialog" aria-labelledby="modal1-label">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h2 class="modal-title">Modal 2</h2>
      </div>
    </div>
  </div>
</div>

答案 1 :(得分:0)

关闭您的HTML标签,它将起作用。 尝试以下运行。

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Modal Example</h2>
  <!-- Trigger the modal with a button -->
  <!-- Dropdown code -->
<div class="dropdown">
  <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">Choose Product <span class="caret"></span></button>
  <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
    <li><a href="#" data-toggle="modal" data-target="#modal1">Open modal 1</a></li>
    <li><a href="#" data-toggle="modal" data-target="#modal2">Open modal 2</a></li>
  </ul>
</div>

<!--Modal code -->
<div class="modal fade" id="modal1" tabindex="-1" role="dialog" aria-labelledby="modal1-label">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h2 class="modal-title">Modal 1</h2>
      </div>
    </div>
  </div>
</div>
<div class="modal fade" id="modal2" tabindex="-1" role="dialog" aria-labelledby="modal1-label">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h2 class="modal-title">Modal 2</h2>
      </div>
    </div>
  </div>
</div>
</div>

</body>
</html>

答案 2 :(得分:0)

感谢您的建议。我已经从头开始对页面进行了重新编码,现在一切似乎都可以使用了(?)。