。click并且此关键字在jquery中不起作用

问题描述 投票:0回答:1

我的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 html function click this
1个回答
0
投票

您的jQuery在文档准备好之前正在加载。用document.ready封装jQuery代码,以便在加载文档后执行]

$(document).ready(function(){
    $("h1").click(function(){
      $(this).text("I have been changed")
    })
});
© www.soinside.com 2019 - 2024. All rights reserved.