twitter-bootstrap 显示一个模态 当 onclick 方法被调用时 <a>

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17288395/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 17:25:01  来源:igfitidea点击:

Showing a modal When onclick method is called of <a>

javascripttwitter-bootstrapsalesforce

提问by Ritesh Mehandiratta

i am using a salesforce platofrm.in which i have access to only onclick function of a button .i have to launch a modal like this code

我正在使用 salesforce platofrm.in,其中我只能访问按钮的 onclick 功能。我必须启动像此代码这样的模式

<!-- Button to trigger modal -->
<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>

<!-- Modal -->
<div id="myModal" class="modal hide fade" 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">
    <p>One fine body…</p>
  </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>

instead of setting these attributes href="#myModal" role="button" class="btn" data-toggle="modal

而不是设置这些属性 href="#myModal" role="button" class="btn" data-toggle="modal

how to show modal when user click on the link using onclick function of javascript please guideline

当用户使用javascript的onclick功能点击链接时如何显示模态请指导

回答by Arun P Johny

On click of the button you can use the showmethod as given in the documentation

单击按钮,您可以使用文档中show给出的方法

$('#myModal').modal('show')

Demo: Plunker

演示:Plunker

回答by nageen nayak

You can use toggle for hide show, don't need to use show and hide

您可以使用切换隐藏显示,不需要使用显示和隐藏

$("#myModalID").modal('toggle');
$('#myModalID').modal('show');
$('#myModalID').modal('hide');