由于某种原因,我的JS在点击不起作用。我有标记的id和类。使用Javascript(“click”)不起作用
<!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肯定是正确的。
你不包括jQuery,所以jQuery不会工作。添加'<脚本 \t \t \t SRC = “https://code.jquery.com/jquery-3.1.1.min.js” \t \t \t完整性= “SHA256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8 =” \t \t \t crossorigin =”匿名“>'到您的HTML。 –
总是检查控制台是否有错误..如果你没有包含jQuery,你会得到一个错误($未定义) –