Javascript 使用 Jquery 在按钮单击时显示模态
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30644342/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Display a Modal on button click using Jquery
提问by Amit
I want to display my Modal on button click. Below is my code.
我想在单击按钮时显示我的模态。下面是我的代码。
<input type="button" id="button1" value="Button" onclick="myFunction()"/>
<div id="openModal" class="modalDialog">
<div>
<a href="#close" title="Close" class="close">X</a>
<h2>
Modal Box</h2>
<p>
Hello world</p>
</div>
</div>
This is my unfinished script.
这是我未完成的剧本。
<script type="text/javascript">
$(document).ready(function () {
});
</script>
回答by Tushar
showopenModal div on button1click.
showbutton1单击openModal div 。
$('#button1').on('click', function() {
$('#openModal').show();
});
No need of onclick="myFunction()"on button
不需要onclick="myFunction()"开button
回答by gabs83
You probably have to set visibility:hidden; to the div, and set it to visible onclick
您可能必须设置可见性:隐藏;到 div,并将其设置为可见 onclick

