我刚刚开始学习Javascript,几乎什么都不懂。我正在尝试将 onclick 事件附加到 HTML 中的元素。
var joinList = function() {
alert("This should display when clicked");
}
document.getElementById("header").onclick = joinList;
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止的代码。当单击具有 header ID 的元素时,不会发生任何事情。我究竟做错了什么?
以下是我的 HTML 代码
<!DOCTYPE html>
<html>
<head>
<title>Testing Page</title>
<script src="testing.js"></script>
</head>
<body>
<h1 id="header">Andrew Dawson</h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用remove类函数.我的jQuery代码如下.
$(document).ready(function() {
$("div.hidden").removeClass("hidden");
});
Run Code Online (Sandbox Code Playgroud)
HTML
<!DOCTYPE html>
<html>
<head>
<title>Testing Page</title>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="testing.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1 class="hidden">Hello World</h1>
<div>Dog</div>
<div class="hidden">Cat</div>
<div>Girl</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
它没有按预期工作.我期望隐藏类的所有div都删除了类,从而导致显示div.
CSS
.hidden {
display: none;
}
Run Code Online (Sandbox Code Playgroud)