我的javascript文件在react应用中没有被加载,我不知道为什么。这是我的javascript文件。react不加载脚本,我需要做什么,所以react加载我的js文件,因为它没有被加载,没有工作,请帮助解决这个问题。 谢谢
edit.js文件 这是我的javascript文件
var buton = document.getElementById("buton");
var allchar = "0123456789ABCDEF";
buton.addEventListener("click", myFun);
function myFun() {
var randcol = "";
for (var i = 0; i < 6; i++) {
randcol += allchar[Math.floor(Math.random() * 16)];
}
document.body.style.backgroundColor = "#" + randcol;
var element = document.getElementById("element");
element.style.color = "#" + randcol;
var btn = document.getElementById("buton");
btn.style.backgroundColor = "#" + randcol;
}
/*-----------------------------------------------------*/
var quotearray = [
" <q>Whatever the mind of man can conceive and believe, it can achieve.</q>",
"<q>You only live once, but if you do it right, once is enough.</q>",
"<q>Life isn’t about getting and having, it’s about giving and being.</q>",
"<q>I attribute my success to this: I never gave or took any excuse.</q>",
"<q>You miss 100% of the shots you don’t take.</q>",
"<q>I’ve missed more than 9000 shots in my career. I’ve lost almost 300 games. 26 times I’ve been trusted to take the game winning shot and missed. I’ve failed over and over and over again in my life. And that is why I succeed.</q>",
"<q>The most difficult thing is the decision to act, the rest is merely tenacity.</q>",
"<q>If a man does his best, what else is there?</q>",
"<q>Every strike brings me closer to the next home run</q>",
"<q>Definiteness of purpose is the starting point of all achievement.</q>",
]
var authorarray = [
"Napoleon Hill",
"Albert Einstein",
"Kevin Kruse",
"Robert Frost",
"Florence Nightingale",
"Wayne Gretzky",
"Michael Jordan",
"Amelia Earhart",
"Babe Ruth",
"W. Clement Stone",
]
function myLost() {
var randNum = Math.floor(Math.random() * 8) + 1;
document.getElementById('element').innerHTML = quotearray[randNum];
document.getElementById('author').innerHTML = authorarray[randNum];
}
buton.addEventListener("click", myLost);
App.js文件
import React, { Component } from'react'
import "./style/style.css"
import {Helmet} from "react-helmet";
class App extends Component{
render(){
return(
<div className="container">
<div className="row align-items-center justify-content-center">
<div className='quote'>
<h2 id="element"><q >quote text</q ></h2>
<p id="author" className="d-flex flex-row justify-content-end p-1">ayoub</p>
<button type="button" className="btn btn getquote" id="buton" >New Quote</button>
<a href="#" class="fa fa-twitter"></a>
<a href="#" class="fa fa-tumblr"></a>
</div>
<footer>Developped By Ayoub Stifi</footer>
</div>
<Helmet>
<script src="/js/edit.js" type="text/babel"></script>
</Helmet>
</div>
);
}
}
export default App;