gpt4 book ai didi

javascript - html 上的内联脚本不起作用?

转载 作者:行者123 更新时间:2023-11-28 04:46:41 26 4
gpt4 key购买 nike

我正在尝试使用组件和 jsx 将静态 HTML 和 Bootstrap 组合重新创建到 React 中。除了这部分之外,代码的其他部分都工作得很好,所以我决定将其保留在 HTML 中,但现在它的图表尚未定义。我可以看到所有文本和背景颜色,但动画除外,动画是隐藏的,并且在控制台中给出图表未定义

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>Jay chacko </title>

<!-- Bootstrap core CSS -->
<link href="../assets/css/bootstrap.css" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="../assets/css/main.css" rel="stylesheet">

<link rel="stylesheet" href="../assets/css/font-awesome.min.css">

<link href='http://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Raleway:400,300,700' rel='stylesheet' type='text/css'>

<script type="text/javascript" src="../assets/js/smoothscroll.js"></script>
<script src="../assets/js/Chart.js"></script>

</head>
<body>
<div id="root"></div>


<!--SKILLS DESCRIPTION -->
<div id="skillswrap">
<div class="container">
<div class="row">
<div class="col-lg-2 col-lg-offset-1">
<h5>SKILLS</h5>
</div>
<div class="col-lg-3 centered">
<canvas id="javascript" height="130" width="130"></canvas>
<p>Javascript</p>
<br>
<script>
var doughnutData = [
{
value: 55,
color:"#1abc9c"
},
{
value : 30,
color : "#ecf0f1"
}
];
var myDoughnut = new Chart(document.getElementById("javascript").getContext("2d")).Doughnut(doughnutData);
</script>
</div>
<div class="col-lg-3 centered">
<canvas id="bootstrap" height="130" width="130"></canvas>
<p>Bootstrap</p>
<br>
<script>
var doughnutData = [
{
value: 80,
color:"#1abc9c"
},
{
value : 10,
color : "#ecf0f1"
}
];
var myDoughnut = new Chart(document.getElementById("bootstrap").getContext("2d")).Doughnut(doughnutData);
</script>
</div>
<div class="col-lg-3 centered">
<canvas id="wordpress" height="130" width="130"></canvas>
<p>jQuery</p>
<br>
<script>
var doughnutData = [
{
value: 40,
color:"#1abc9c"
},
{
value : 35,
color : "#ecf0f1"
}
];
var myDoughnut = new Chart(document.getElementById("wordpress").getContext("2d")).Doughnut(doughnutData);
</script>
</div>

<div class="col-lg-3 col-lg-offset-3 centered">
<canvas id="html" height="130" width="130"></canvas>
<p>HTML/CSS</p>
<br>
<script>
var doughnutData = [
{
value: 95,
color:"#1abc9c"
},
{
value : 20,
color : "#ecf0f1"
}
];
var myDoughnut = new Chart(document.getElementById("html").getContext("2d")).Doughnut(doughnutData);
</script>
</div>
<div class="col-lg-3 centered">
<canvas id="photoshop" height="130" width="130"></canvas>
<p>Angular Js</p>
<br>
<script>
var doughnutData = [
{
value: 65,
color:"#1abc9c"
},
{
value : 30,
color : "#ecf0f1"
}
];
var myDoughnut = new Chart(document.getElementById("photoshop").getContext("2d")).Doughnut(doughnutData);
</script>
</div>
<div class="col-lg-3 centered">
<canvas id="illustrator" height="130" width="130"></canvas>
<p>React</p>
<br>
<script>
var doughnutData = [
{
value: 50,
color:"#1abc9c"
},
{
value : 50,
color : "#ecf0f1"
}
];
var myDoughnut = new Chart(document.getElementById("illustrator").getContext("2d")).Doughnut(doughnutData);
</script>
</div>
<p>Other Skills - UNIX Commands, NPM, Gulp, bower packages, Web packs </p>
<p>Other Soft Skills - NOSQL,MYSQL, Node JS </p>
<p>Other Softer Skills - C#, Java, Objective C, MYSQL, PHP, Python </p>


</div>
<br>
</div>
</div>




<script src="../assets/js/jquery.min.js"></script>
<script src="../assets/js/bootstrap.js"></script>

</body>
</html>

最佳答案

可能是由于浏览器异步加载../assets/js/Chart.js导致的。

尝试在代码开头添加 console.log(Chart)(加载 Chart.js 文件后),看看它是否在控制台中打印。

如果它存在,那么首先加载它就不是问题。 (这个答案可能对你没有帮助)

如果显示未定义,请在浏览器控制台中输入Chart,看看它现在是否异步加载并已定义。如果它出现,您必须确保图表已加载然后运行您的代码。

关于javascript - html 上的内联脚本不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43302264/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com