I have created one js file in our application. in this js file How add in our page?
I had Written below code for our application. First of I had written online link that's work perfect. then after download js and set path to js file. but not proper working.
ponentDidMount() {
const script = document.createElement("script");
// script.src = ".12.4.min.js";
script.src = "../../Content/JS/jquery-1.12.4.min.js";
script.async = true;
document.body.appendChild(script);
}
I have created one js file in our application. in this js file How add in our page?
I had Written below code for our application. First of I had written online link that's work perfect. then after download js and set path to js file. but not proper working.
ponentDidMount() {
const script = document.createElement("script");
// script.src = "https://code.jquery./jquery-1.12.4.min.js";
script.src = "../../Content/JS/jquery-1.12.4.min.js";
script.async = true;
document.body.appendChild(script);
}
Share Improve this question asked Jan 7, 2019 at 6:19 Diamond KingDiamond King 67610 silver badges17 bronze badges 5-
install those packages by
npm install {package name}
– Vikas Singh Commented Jan 7, 2019 at 6:21 - which one package install ?? – Diamond King Commented Jan 7, 2019 at 6:23
-
as i can see you want to use Jquery in project then you can install it by
npm install --save jquery
or through your package manager – Vikas Singh Commented Jan 7, 2019 at 6:25 - I have already install this package. but can't add to external js file. – Diamond King Commented Jan 7, 2019 at 6:32
- put js file within src folder and import this file and put it in script tag anywhere inside your project. – Mustkeem K Commented Jan 7, 2019 at 6:34
2 Answers
Reset to default 2If you want to add additional js file (script). This is the easiest way to to do this.
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<script src="../../Content/JS/jquery-1.12.4.min.js"></script>
</body>
This is the root html file of your react application. According to your folder structure path can be changed.
You need to install and then import jQuery or any other plugin you need in your ponent.
npm install {package name}
in your package JSON.
import jquery from 'jquery'
in your ponent
Here is an example
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745345345a4623518.html
评论列表(0条)