我的jquery事件功能不起作用。这是我保存在jquery.js文件中的jquery代码:
$("h1").click(function(){
$(this).text("I have been changed")
})
以下是我具有链接jquery.js文件的相应html代码
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>jquery</title>
<script
src="https://code.jquery.com/jquery-3.4.1.js"
integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="
crossorigin="anonymous"></script>
<script src="jquery.js"></script>
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
crossorigin="anonymous">
</head>
<body>
<h1>Selecting with jquery</h1>
<ul>
<li>understanding</li>
<li>analyzing</li>
<li>implementing</li>
</ul>
</body>
您的jQuery在文档准备好之前正在加载。用document.ready封装jQuery代码,以便在加载文档后执行]
$(document).ready(function(){
$("h1").click(function(){
$(this).text("I have been changed")
})
});