我试图让下面的代码在我的MVC 5项目的工作:警戒关闭按钮不Bootstrap与ASP.NET MVC工作
<!-- for the snippet to work -->
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<p>This alert should close, when clicking the 'x'-button:</p>
<div class="alert alert-warning alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span>
</button>
<strong>Holy guacamole!</strong> Best check yo self, you're not looking too good.
</div>
我把它从official bootstrap site。当点击'x'按钮时,警报应该关闭。正如你所看到的,它在这段代码中实际上工作正常。但它不在我的应用程序中。警报确实没有关闭。很显然,MVC框架必须为此负责。
浏览器的调试控制台不显示任何错误消息。是的,我还在项目中加入了Bootstrap(3.5.5)和jQuery(2.1.4)的JS源代码 - 它们在浏览器的调试视图中正确加载并显示在'sources'下。
编辑:亚伦建议其他一些脚本可能会覆盖/隐藏引导代码。所以这些都是JS库我的项目目前使用:
- jQuery的2.1.4.min.js
- bootstrap.min.js
- jquery.unobtrusive-ajax.min.js
- 的jQuery -ui-1.11.4.min.js
- jquery.effects.highlight.min.js
- jquery.effects.core.min.js
- 加上其他一些手写的帮手JS与辅助方法
它们的加载顺序与列出的顺序相同。遗漏以下库并没有帮助:
- 的jQuery-UI-1.11.4.min.js
- jquery.effects.highlight.min.js
- jquery.effects.core.min.js
删除jquery.unobtrusive-ajax.min.js会导致我的应用程序“崩溃”,因为它无法再动态加载内容。
下面的匿名函数声明被调用,当文件被加载(前的警报已被动态插入到HTML):
Alert.prototype.close = function (e) {...}
点击“X'键好像不叫bootstrap.js中的任何代码,但也许我只是没有找到放置断点的正确位置。
你可以创建jsfiddle吗? – Win
是的,jsfiddle和bootply也可以工作 – wodzu
嗯,它只发生在你的参与项目中。您需要删除所有JavaScript并将它们重新放回一次。 – Win