Javascript on ("click") not working
Javascript on ("click") not working
由于某种原因,我的JS点击不工作。我有id和类标记。
<!DOCTYPE html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type='text/javascript' src="js/index.js"></script>
<script>
$(document).ready(function(){
alert("Hello World");
});
</script>
</head>
<div class="container-fluid">
<div class = "row text-center">
<h2>Cat Photo Finder</h2>
</div>
<div class = "row text-center">
<div class = "col-xs-12 well message">
The message will go here
</div>
</div>
<div class = "row text-center">
<div class = "col-xs-12">
<button id = "getMessage" class = "btn btn-primary">
Get Message
</button>
</div>
</div>
</div>
这是Javascript。
$(document).ready(function() {
// Only change code below this line.
$("#getMessage").on("click", function(){
$(".message").html("Get message");
});
// Only change code above this line.
});
我真的很感激你的真知灼见!非常感谢。我的假设是index.js文件没有正确链接,但src绝对是正确的。
$(document).ready(function() {
$("#getMessage").on("click", function(){
alert('You Clicked..!!');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container-fluid">
<div class = "row text-center">
<h2>Cat Photo Finder</h2>
</div>
<div class = "row text-center">
<div class = "col-xs-12 well message">
The message will go here
</div>
</div>
<div class = "row text-center">
<div class = "col-xs-12">
<button id = "getMessage" class = "btn btn-primary">
Get Message
</button>
</div>
</div>
</div>
您忘记包含脚本,如果没有,您可能会错过对齐脚本文件,请先加载它
如果你打算使用某个库的功能——在这个例子中是jQuery——那么你必须在使用它的任何功能之前加载这个库。
$(document).on("click", "#getMessage", function(){
$(".message").html("Get message");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container-fluid">
<div class = "row text-center">
<h2>Cat Photo Finder</h2>
</div>
<div class = "row text-center">
<div class = "col-xs-12 well message">
The message will go here
</div>
</div>
<div class = "row text-center">
<div class = "col-xs-12">
<button id = "getMessage" class = "btn btn-primary">
Get Message
</button>
</div>
</div>
</div>
您可能缺少jQuery脚本文件。这对我来说很合适。
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
<script>
$(document).ready(function () {
alert("Hello World");
});
$(document).ready(function () {
$("#getMessage").on("click", function () {
$(".message").html("Get message");
});
});
</script>
</head>
<body>
<div class="container-fluid">
<div class="row text-center">
<h2>Cat Photo Finder</h2>
</div>
<div class="row text-center">
<div class="col-xs-12 well message">
The message will go here
</div>
</div>
<div class="row text-center">
<div class="col-xs-12">
<button id="getMessage" class="btn btn-primary">
Get Message
</button>
</div>
</div>
</div>
</body>
</html>
相关文章:
- 铬:“;未捕获的语法错误:意外的标记:"
- jQuery is not loaded
- AngularJS JSON not arriving php
- 可以设置“;文件名"发生错误时显示的内联脚本标记的
- JS表单提交"无法使用Chrome数据保护程序加载此页面.尝试重新加载页面.调试信息:POST CISmtuK
- 检测电话窃听,即:<a href="电话:xxx">在UIWebview上
- $rootScope not working
- reactRedux is not defined
- jQuery document.ready not working
- 使用“+="操作人员
- //而不是在src=“”上使用http://"属性
- "未捕获的语法错误:意外的标记}"
- 可以<脚本类型=“;text/javascript”>window.location=“/"</
- "实例范围”;TypeScript类的getter/setter
- Javascript复选框函数:;缺少:在属性id之后"
- Javascript/Jquery Blob not showing Chrome PDF
- ReferenceError: not defined
- "“;变量未引用正确的对象
- JavaScript/jQuery - "$ is not defined- $function()"
- How do i formulate "if this.children.has.not.class"