Button 点击事件引导按钮
当您单击引导按钮时,如何对其进行编码以打开模式?我需要JavaScript吗?我应该把它放在哪里 这是我的代码的副本,当前不起作用:Button 点击事件引导按钮,button,onclick,bootstrap-4,bootstrap-modal,buttonclick,Button,Onclick,Bootstrap 4,Bootstrap Modal,Buttonclick,当您单击引导按钮时,如何对其进行编码以打开模式?我需要JavaScript吗?我应该把它放在哪里 这是我的代码的副本,当前不起作用: <!-- Trigger the modal with a button --> <button type="button" class="btn btn-info btn-lg" data-target="#myModal">Search Date/Time Select</button>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-target="#myModal">Search Date/Time Select</button>
<!-- Modal -->
<div id="myModal" class="modal hide fade" role="dialog" bootstrap-toggle-modal="myModal" aria-hidden="true">
<div class="modal-dialog">
<!--Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Date/Time Select</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
是的,您确实需要Javascript来实现此功能。具体来说,jQuery和Popper.js。BootStrap还有许多其他JavaScript插件 如果这不适用于您,请检查您的index.html是否按照 此代码按照 我不推荐它,但如果您希望使用早期版本:
我把上面的代码粘贴到了我的索引中,它消失了,但是保留页面加上弹出窗口是模态的。我不完全确定你对上面说的是什么?我提供的第二个代码片段提供了一个按钮,单击该按钮会打开一个模式,这是您最初要求的吗?我的建议是仔细阅读Bootstrap4文档。。。。这只是数据切换=模式。。是的,
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Hello, world!</title>
</head>
<body>
<h1>Hello, world!</h1>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>