打开最接近jQuery点击元素的模态

时间:2014-12-31 04:11:10

标签: jquery twitter-bootstrap

我根据点击的标签弹出最近模式时出现问题。不明白为什么我的jQuery不起作用。

   <div class="col-md-3">
        <h2 class="text-center"> gMaps XML </h2> 

   <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
      <div class="modal-dialog modal-lg">
        <div class="modal-content">
          <p>this is a test of xml modal</p>
        </div>
      </div 
   </div>

      <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam</p>
   <!-- makes above modal pop-up -->   <a href="#" class="code button white text-center" data-toggle="modal">View Code</a>
</div> <!-- END COL -->


<div class="col-md-3" >
   <h2 class="text-center"> Date JS </h2> 
 <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria labelledby="myLargeModalLabel" aria-hidden="true">
   <div class="modal-dialog modal-lg">
    <div class="modal-content">
       This is a test
    </div>
  </div>
</div>

<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore .</p>
 <!-- This clicked --> <a href="#" class="code button white text-center" data-toggle="modal" >View Code</a>

<script>
$("a.code").click(function(event){
   $(this).closest(".bs-example-modal-lg").modal("show");
  });
</script>

1 个答案:

答案 0 :(得分:2)

试试这个。我希望这会对你有所帮助。

$("a.code").click(function(event){
   $(this).parent().find(".bs-example-modal-lg").modal("show");
  });

<强> Fiddle Demo