无法在点击链接时显示模态

时间:2016-07-19 22:09:11

标签: javascript jsp

我想点击一个链接打开一个模态。然而,它没有开放。以下是链接的代码:

<div class="span4" style="font-size: 14px">             
   <a href="#" onClick="openModal(); return false;" cssClass="view-more" >Some<br>textlater</a>
</div>

这是模态的代码

   <div class="modal hide fade" id="myDiv" style="width: 520px;display: block;border: 1px solid black">
 <div class="modal-header" style="width: 517px;"><button type="button" class="close" data-dismiss="modal" aria-hidden="true" >&times;</button></div>    
 <div class="modal-body"">
 <div id="mydiv1" style="text-align:center;">
    <div class="span9"><img alt="img" style="margin-bottom: 10px;padding-top: 2px" src="./images/img.png"></div>
</div>    
</div> 
<div class="modal-footer">
<div class="button-bar-footer">
        <div class="row">
            <div class="pull-left">
                <s:a href="#" cssClass="btn btn-link btn-back" data-dismiss="modal">
                    <span><s:text name="generic.cancel" /></span>
                </s:a>
            </div>
            <div class="pull-right">
             <button type="button" class="btn btn-success" data-dismiss="modal">Close</button>                                  
            </div>
        </div>
  </div>
  </div>
  </div>

这是功能

  <script type="text/javascript">
    function openModal(){
       alert("hello");
       $('myDiv').modal('show');
    }

PLease指南哪里缺少?

1 个答案:

答案 0 :(得分:0)

我发现了这个问题。在调用show modal之前我错过了#。以下是修改后的代码

<script type="text/javascript">
   function openModal(){
      alert("hello");
   $('#myDiv').modal('show');
 }