javascript - boostrap toggle="buttons" 阻止A标签的默认行为的问题

查看:171
本文介绍了javascript - boostrap toggle="buttons" 阻止A标签的默认行为的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

父标签添加data-toggle="buttons" 属性之后,子元素A标签的默认行为会不阻止。一下是DOM结构

<div class="btn-group btn-group-sm" data-toggle="buttons" style="margin-left:3px;">

<a class="btn btn-info active" href="http://localhost:8082/下拉问题修复完成版.rar">   
    <span class="glyphicon glyphicon-download-alt"></span>模板下载    
</a>    
<button class="btn btn-success" data-toggle="modal" data-target="#subjectEdit">    
    <span class="glyphicon glyphicon-th"></span>专题编辑    
<button>    

</div>

点击A标签是不会有任何反应的。这边不清楚boostrap阻止A标签的目的是什么,所以看了一下事件绑定的源码。大概是这样的!


  if (!($(e.target).is('input[type="radio"], input[type="checkbox"]'))) {          
        // Prevent double click on radios, and the double selections (so cancellation) on checkboxes    
    e.preventDefault()    
    
    // The target component still receive the focus    
    if ($btn.is('input,button')) $btn.trigger('focus')    
    else $btn.find('input:visible,button:visible').first().trigger('focus')

  }

// Prevent double click on radios, and the double selections (so cancellation) on checkboxes
我英语水平不咋地,有道加蒙,这句我理解的意思是 阻止在radios和ckeckbox表单双击,避免双击变成取消选中。
好,到这里我就更蒙逼了,既然是阻止双击,为啥这一句$(e.target).is('input[type="radio"], input[type="checkbox"]')还要做一下非运算。思前想后就是想不明白。

论坛里有大神指教一下咯

解决方案

这里的双击指的是btn是label标签的时候会点击的时候会多触发一次input的点击事件,这个事件会冒泡再触发一次引起按钮的双击。用e.preventDefault()阻止label标签的默认行为

这篇关于javascript - boostrap toggle=&quot;buttons&quot; 阻止A标签的默认行为的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆