gpt4 book ai didi

javascript - 是否可以将字符串数据从 javascript 传递到 html 文件?

转载 作者:行者123 更新时间:2023-11-28 10:45:17 27 4
gpt4 key购买 nike

我有两个文件,“a.js”和“b.html”。是否可以将从“a.js”创建的字符串数据附加到“b.html”头标记?这是我从“a.js”文件中组装字符串数据的代码。

a.js:

createChart: function () {
var pieChartScript1 =
'<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>' +
'<script type="text/javascript">' +
'google.charts.load("current", {packages:["corechart"]});' +
'google.charts.setOnLoadCallback(drawChart);' +
'function drawChart() {' +
'var data = google.visualization.arrayToDataTable([';

var pieChartScript2 = '[' + '0~999' + ', ' + one.length + '],';
pieChartScript2 += '[' + '1000~1999' + ', ' + two.length + '],';
pieChartScript2 += '[' + '2000~2999' + ', ' + three.length + '],';
pieChartScript2 += '[' + '3000~3999' + ', ' + four.length + '],';
pieChartScript2 += '[' + '4000~4999' + ', ' + five.length + '],';
pieChartScript2 += '[' + '5000~' + ', ' + six.length + ']]);';

var pieChartScript3 =
'var options = {title: ' + '제목' + ',pieHole: 0.4,};' +
'var chart = new google.visualization.PieChart(document.getElementById("donutchart"));' +
'chart.draw(data, options);}' +
'</script>';
console.log(pieChartScript1 + pieChartScript2 + pieChartScript3);
},

我希望将其附加到“b.html”文件中

b.html:

<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<!--I wish to append it here-->
<body>

<div id="piechart" style="width: 900px; height: 500px;"></div>

</body>

</html>

最佳答案

如果你想使用这个js文件,你必须在html文件中使用。我不知道如何将js字符串作为你要求的函数运行。

关于javascript - 是否可以将字符串数据从 javascript 传递到 html 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44584158/

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