I used to think that script can be placed anywhere in HTML. I corrected my misconception when I made a request today - the location of script is not random. First of all, I want to implement a select tag with two options: yes and no. However, during initialization, the select tag is required to select a null value by default, so I added a method to let it change the null value when clicking. Delete: $('#checkcash').click(function () { if ($('#checkcash').val() == '0') { $("#checkcash option[value='0']").remove(); } }); $("#alert").click(function(){ alert("1123"); }) 是否已提现 是 否 Copy after login But this does not achieve the desired effect. At first I thought it was a jquery syntax error and I kept checking and correcting it online, but it didn’t work. Then I suddenly thought about it. I should have put the script at the back and tried it. It turned out to be ok. Then I suddenly realized that it was not like this. Later I checked the reason is because the html file is executed in a top-down manner, but the order of the imported css and javascript is different. When the css is introduced for execution and loading, the program The execution continues, and when the script is executed, the thread is interrupted, and the program continues execution only after the execution of the script is completed. Therefore, the script is generally placed after the body to avoid delayed blocking due to long execution of the script. To achieve the effects of some pages, some js scripts need to be dynamically loaded in advance, so these scripts should be placed before <body>. <span style="color: #ff0000;">Secondly, the js that needs to access the dom element cannot be placed before the body, because the dom has not yet started to be generated, so the js that accesses the dom element before the body will error or be invalid. <span style="color: #000000;">It is because of this that I added methods to the dom before it was generated, which led to this. </span></span></p> <p><span style="color: #ff0000;"><span style="color: #000000;"># I really should study a lot of things and think so, but I didn’t delve into it. Keep working hard in the future! </span></span></p> <p> ps: In fact, there is another way, which is to use jquery's initialization page method to add the click <a href="http://www.php.cn/js/js-jspopular-guide-event.html" target="_blank"> event </a> added to the label above to $(function (){}) is also possible. The principle is the same as above. This method is executed after the page is loaded, so it can be placed anywhere! </p>