jquery,javascript在引导程序中不起作用
jquery, javascript not working in bootstrap
我正在使用JQuery和bootstrap,当我试图单击应该调用该函数的按钮时,它不起作用。我看了开发者控制台,什么都没有,有人知道吗?
<html>
<head>
<title>Bill</title>
<link rel="stylesheet" href="css/bootstrap.min.css"/>
<link rel="stylesheet" href="css/jumbotron-narrow-me.css"/>
<script src="js/jquery-2.1.3.min.js"/>
<script src="js/bootstrap.min.js"/>
<script type="text/javascript">
var count=0;
$('#ocs').click(function(){
count++;
$('#cookies').html('0Cs : ' + count);
});
</script>
</head>
<body>
<div class="jumbotron">
<p class="lead">
welcome to opposition clicker, its amazing. it has one upgrade.
"opposition" when you get this, you will get +100 0Cs' every second.
</p>
<br><br/>
</div>
<div class="container" id="cookies">aasasa</div>
<button id="ocs" type="button" class="btn btn-lg btn-success">0Cs'</button>
</body>
</html>
您只需要正确关闭一些脚本标记并放置脚本底部:-)
<html>
<head>
<title>Bill</title>
<script data-require="jquery@*" data-semver="2.1.3" src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<link data-require="bootstrap@*" data-semver="3.3.1" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" />
<script data-require="bootstrap@*" data-semver="3.3.1" src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="jumbotron">
<p class="lead">
welcome to opposition clicker, its amazing. it has one upgrade.
"opposition" when you get this, you will get +100 0Cs' every second.
</p>
<br />
<br />
</div>
<div class="container" id="cookies">aasasa</div>
<button id="ocs" type="button" class="btn btn-lg btn-success">0Cs'</button>
<script type="text/javascript">
var count=0;
$('#ocs').click(function(){
count++;
$('#cookies').html('0Cs : ' + count);
});
</script>
</body>
</html>
Plunker
附言:-我没有在示例中添加jumbotron-n窄带.css,因为它在plunker上不可用,但希望它能有所帮助:-)
确保在DOM准备就绪后声明您的点击处理程序
比如:
$(document).ready(function(){
$('#ocs').click(function(){
// something
});
});
今天我找到了这个问题的解决方案。如果有人在2022年遇到同样的问题,那么你只需要使用下面给出的脚本标签和Jquery标签:
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link rel="stylesheet"
href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-3.6.0.js" ></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
使用.text()函数而不是.html()
试试这个:
$(function(){
$(document).on('click','#ocs',function(e){ // do somethign here
});
});
相关文章:
- Nano Scroller在引导程序DropDown和Model Box中不起作用
- 引导程序选择在jquery pep中不起作用
- 引导程序3.3.4工具提示不起作用
- 为什么我的引导程序的下拉菜单不起作用
- Jquery 引导程序验证 asp.net 母版页不起作用
- 引导程序的下拉列表不起作用
- 转换元素在引导程序中不起作用
- 引导程序弹出窗口(bootbox)中的Javascript事件不起作用
- jquery,javascript在引导程序中不起作用
- 为什么引导程序在小屏幕上不起作用
- Twitter引导程序示例在IE8中不起作用
- Magento Jquery引导程序和原型冲突?导航标签不起作用
- Twitter引导程序弹出在网站上不起作用:未获取引用错误
- 引导程序3在IE8中不起作用(已检查其他答案)
- 引导程序下拉菜单doen'不起作用
- 引导图示符在java Web应用程序中不起作用
- 选项“;daysOfWeekDisabled”;在引导程序日期时间选择器中不起作用
- KnockoutJS - 引导程序 3 模式绑定不起作用
- 轮播引导程序在 IE 10 中不起作用
- 弹出窗口中的溢出滚动条不起作用(引导)