Home > Article > Web Front-end > How to write external js to call jquery
Before using an external js file to call the jQuery library, you need to confirm whether the jQuery library has been referenced in the page. If it is not referenced, you need to reference the jQuery library first in the html file.
The following are the steps for general external js files to call the jQuery library:
$(document).ready(function(){ // js代码内容 });
$(document).ready(function(){ $('body').html($('body').html().replace(/关键词/g, '替换词')); });
<script src="sample.js" type="text/javascript"></script>
In this way, after the page is loaded, the relevant code in the sample.js file will be automatically executed. .
It should be noted that if you need to use other plug-ins or methods of jQuery in the sample.js file, you need to introduce other plug-ins or methods after introducing the jQuery library, otherwise you may be unable to call the jQuery function. Condition.
The above is the detailed content of How to write external js to call jquery. For more information, please follow other related articles on the PHP Chinese website!