Uncaught TypeError: $(...).makeRed is not a function

Uncaught TypeError: $(...).makeRed is not a function

我想用 jquery 选择器调用自定义 javascript 函数,但是这说 Uncaught TypeError: $(...).makeRed is not a function

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<h3 id="ch">Hello Wrld</h3>

</body>
</html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<script>
    $(document).ready(function(){
        $.fn.makeRed = function(){
            this.html('welcome to all');
            return this;
    }
});
    $('#ch').makeRed();


</script>

您在就绪状态创建之前调用 makeRed。把它放在 }); 里面 这是固定的片段。 :)

    $(document).ready(function(){
        $.fn.makeRed = function(){
            this.html('welcome to all');
            return this;
    }
     $('#ch').makeRed();
});
   
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<h3 id="ch">Hello Wrld</h3>

</body>
</html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>