Why can't $(this). Children ('option:selected') get a value?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <!-- <script src="../js/jquery.js"></script> -->
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <title>Document</title>
    <script>
    $(function(){
        // $("select[name="mySelect"]").on("change",(e)=>{
        $("-sharpaa").on("change",(e)=>{
            console.log(1111);
            console.log("value", $("-sharpaa").val());
            console.log("e",e.target.value);
            let this_val = $(this).children("option:selected").val();
            console.log("this_val",this_val);
        });
    })
    </script>
</head>
<body>
    <select name="mySelect" id="aa">  
        <option value="1">one</option>  
        <option value="2">two</option>  
        <option value="3">three</option>  
    </select> 
</body>
</html>

my select chose not to get the current obtained value through $(this). Later, I read online that I asked for $(this). Children ("option:selected");
but I don"t know why it"s always undefined?

Jul.28,2021

you used the arrow function = > the direction of this is not what you thought $('- sharpaa').


you should understand the function of the arrow function and why the arrow function
arrow function does not have its own this his this is from the outer scope


just change the arrow function to a normal function function

The

arrow function is equivalent to

(function() {}).bind(this);

jquery usually binds a this, dynamically when executing a callback function, so in jquery, you usually don't bind this, or use arrow functions.


the this in the brother arrow function is the this, in the current scope. To put it simply, this points to confusion, you can bind it with bind, or you can abandon the use of the arrow function, so it will be bound to the object that should be clicked.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea866a-47ca9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea866a-47ca9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?