<分区>
标签 javascript jquery html css
<分区>
我正在学习 Codacademy 类(class),界面告诉我 jQuery 点击监听器无法正常工作。我不明白为什么。
我的 HTML 代码是:
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="style.css" />
<script src='script.js' type="text/javascript"></script>
</head>
<body>
<button id="button">change this</button>
<div id="change_me">
</div>
</body>
</html>
我的 CSS 代码是:
#change_me {
color: green;
}
我的 JS 代码是:
$(document).ready(function() {
$("#button").click(function() {
//$(#change_me).text("I have been changed!");
$(#change_me).text( "Handler for .click() called." );
});
});
有什么建议吗?谢谢。
最佳答案
您在 id
选择器周围遗漏了引号 "
,因此您应该替换:
$(#change_me)
作者:
$("#change_me")
希望这对您有所帮助。
$(document).ready(function() {
$("#button").click(function() {
//$(#change_me).text("I have been changed!");
$("#change_me").text( "Handler for .click() called." );
});
});
#change_me {
color: green;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="button">change this</button>
<div id="change_me"></div>
关于javascript - jQuery 点击监听器无法正常工作 - 已关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34464008/