You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Bootstrap Modal点击触发按钮无响应无法弹出问题求助

问题排查&修复方案

  • 版本不兼容问题:你加载的Bootstrap资源版本完全不匹配,bootstrap.min.css是v4.0.0版本,bootstrap.min.js是v3.3.7版本,两个大版本的模态框实现逻辑、DOM结构要求都有差异,直接导致功能失效。请统一使用同版本的Bootstrap资源。
  • ID匹配错误:模态框的id属性末尾多了多余空格,你写的是id="employeedropdownscan ",而按钮data-target指向的是#employeedropdownscan,二者完全不匹配,Bootstrap找不到对应的模态框元素。
  • HTML语法错误:触发按钮的代码末尾多了一个无效的双引号:<input ... value="Click Here" ">,多余的引号会导致浏览器解析标签属性出现异常。
  • 多余空格问题:你所有HTML属性末尾都加了不必要的空格,虽然大部分场景不影响,但建议清理避免出现意外的选择器匹配问题。

修复后的完整代码

<!-- 统一使用Bootstrap4资源,jQuery版本匹配Bootstrap4要求 -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

<!-- 清理多余引号,data-target和模态框ID对应 -->
<input class="button" type="button" data-toggle="modal" data-target="#employeedropdownscan" value="Click Here">

<!-- 清理ID和所有属性的多余空格 -->
<div class="modal fade" id="employeedropdownscan" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
        <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
        </button>
        </div>
        <div class="modal-body">
          ...
        </div>
        <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
        </div>
    </div>
  </div>
</div>

如果需要保留Bootstrap3版本,只需要把CSS换成3.3.7版本的对应文件即可,同时去掉modal-dialog-centered类,该类是Bootstrap4新增的,Bootstrap3不支持。

内容的提问来源于stack exchange,提问作者NicLovin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 06:36:04