What's the difference between writing js, in the < script > tag in html and writing js in the imported js file?

when I use the jquery chosen drop-down plug-in, I put the initialization code

$("-sharpmaintainerName").chosen();
When

is written in the imported js file, the plug-in cannot be used and the style can be loaded, but clicking the drop-down box does not respond.

but as long as I write this line of code in the < script > of the current html, everything will be fine.

what"s the difference between writing js, in the < script > tag in html and writing js in the imported js file?

Thank you

May.30,2021

js files are introduced externally, while those in html are written internally.
externally introduced js can be applied to multiple html pages at the same time, which will have better expansibility and maintainability.
internally written js can only be applied to current html files

The problem with the execution of the

method may be the introduction order of js, or the fact that your DOM structure is dynamically loaded


it is recommended that you check the order of the imported files and see if there are any errors reported on the console.

"but as long as I write this line of code in the < script > of the current html, everything will be fine." Make sure that you write directly in html and import external js files in the same location.

or change the imported js file to the following try

$(function(){
    $('-sharpmaintainerName').chosen();
})

makes no difference, external references are also available on other pages;
as for what you said doesn't work, it may be that you quoted in the wrong location;
before the end of the body tag, introduce the plug-in first, and then introduce the js file you wrote to try


Thank you very much for your answer. I tried everything you said, although it was unsuccessful. It's probably due to my carelessness or unfamiliarity with vue. Later, I used other implementation methods, and everything went well. Thank you very much

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-1b37428-2b3e2.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-1b37428-2b3e2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?