在 html 中的警报(或对话框)上显示下拉列表

Kis*_*N R 3 html javascript css jquery bootstrap-4

我的项目要求是在单击按钮时显示警报或对话框,在该警报上,显示带有一些值的下拉列表,选择下拉列表值并使用 HTML 将其保存在数组列表中。我试过这个, 但它不起作用。警报对话框应如下图所示。

<!-- 开始片段:js hide: false 控制台:

<html lang="en">
 <head>
  <title></title>
 <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
 <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
 <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
 </head>
 <body>

<a data-target="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>

<div class="modal fade hide" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Modal header</h3>
  </div>
  <div class="modal-body">
    <select>
              <option>test</option>
              <option>test</option>
              <option>test</option>
              <option>test</option>
              <option>test</option>
          </select>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-primary">Save changes</button>
  </div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

Cha*_*har 5

试试这个代码...

<a data-target="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

  <div class="modal-dialog">
  <div class="modal-content">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Modal header</h3>
  </div>
  <div class="modal-body">
    <select>
              <option>test</option>
              <option>test</option>
              <option>test</option>
              <option>test</option>
              <option>test</option>
          </select>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-primary">Save changes</button>
  </div>
  </div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

https://codepen.io/chandrashekhar/pen/yXNBmQ?editors=1100

这是一个链接供参考

您已将隐藏类添加到模态,并且还漏掉了一些代码,试试这个吧。。