Problems in learning jQuery for the first time

Time:2020-3-31

jQuery

JQuery first impression

I always hear that jQuery is very easy to use, especially when setting styles, it encapsulates many methods to make others use it better. I tried it for the first time today and found many problems

Problems in using jquery

When used, it often appearsReferenceError:$ is not defined, may be used for the first time, so you don’t know that you need to put jQuery first when referencing it.

After performing the above operation, the error still exists. Here is my code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    < title > 01 - event < / Title >
    <script type="text/javascript" charset="utf-8" async defer></script>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        .box{
            height: 30px;
            width: 120px;
            border: 1px solid #55E6C1;
            margin: 10px;
            text-align: center;
            line-height: 30px;
            font-weight: 600;
            font-size: .8em;
        }
        #showBox{
            width: 70px;
            height: 20px;
            /* border: 1px solid black; */
            position: relative;
            left: 165px;
            top: -115px
        }
    </style>
</head>
<body>
    <div class="box" id="box1">switch</div>
    Button 1 < / div >
    Button 2 < / div >
    <div id="showBox"></div>
    <script type="text/javascript">
        $(function(){
            $("#box").click(function(){
                alert('hello world');
            })
        })
    </script>
</body>
</html>

It’s only when you look at it carefully, becauseasync deferThese two properties prevent the code from running, in order to load the web page fasterJavaScriptScripts usually use this property, but there will be problems when using jQuery!!

JQuery advantages

When using, I am not used to the continuity of jQuery. Although it is convenient for us to use, I can only slowly adapt to the different usage habits of JavaScript and jQuery. In general, jQuery is very easy to use, but I think I have to stay in the pit. I hope someone can give me some advice, Daniel, don’t spray!

Finally, reference jquery

Write less,do more
Write less, do more

PS: markdown is also learned today. Don’t spray~~~~

Recommended Today

PHP Basics – String Array Operations

In our daily work, we often need to deal with some strings or arrays. Today, we have time to sort them out String operation <?php //String truncation $str = ‘Hello World!’ Substr ($STR, 0,5); // return ‘hello’ //Chinese string truncation $STR = ‘Hello, Shenzhen’; $result = mb_ Substr ($STR, 0,2); // Hello //First occurrence of […]