Bootstrap:禁用模态链接(role =“button”)

时间:2017-03-27 18:34:46

标签: jquery twitter-bootstrap modal-dialog disabled-control

我的模态工作正常,但我想暂时禁用链接(角色按钮)。 我找到了解决方案但没有工作:

<span  data-target="#myModal"> 
<a href="#" id="disabled_share" class="btn-xs btn-info" role="button" data-toggle="tooltip" data-placement="bottom" title="title"><i class="fa fa-share-alt" aria-hidden="true"></i></a>
</span>

                <div id="myModal" class="modal fade">
                 <div class="modal-dialog">
                  <div class="modal-content">
                   <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title">Modal</h4>
                   </div>
                   <div class="modal-body">
                        Modal body
                   </div>
                   <div class="modal-footer">
                    <button type="button" class="btn btn-default btn-xs" data-dismiss="modal"><i class="fa fa-times-circle" aria-hidden="true"></i> Close</button>
                   </div>
                  </div>
                 </div>
            </div>

和Jquery:

<script type="text/javascript">
$('#disabled_share').addClass('disabled');  
</script>   

如何解决这个问题?

由于

1 个答案:

答案 0 :(得分:1)

这是达到要求的正确方法。

将boostrap类“禁用”添加到您的链接并检查链接上的onclick事件。您可以根据需要添加或删除“禁用”类。

每当你在≶a&gt;内没有href链接时,还有一件事然后使用javascript:void(0);

$("#disabled_share").on("click",function(){
  if(!($(this)).hasClass("disabled")) {
	$('#myModal').modal('show');
  }
});
<span> 
  <a href="javascript:void(0);" id="disabled_share" class="btn-xs btn-info disabled" role="button" data-toggle="tooltip" data-placement="bottom" title="title">
      <i class="fa fa-share-alt" aria-hidden="true"></i>
  </a>
</span>

<div id="myModal" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal</h4>
      </div>
      <div class="modal-body">
        Modal body
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default btn-xs" data-dismiss="modal"><i class="fa fa-times-circle" aria-hidden="true"></i> Close</button>
      </div>
    </div>
  </div>
</div>