简体   繁体   English

如何将一个数字从 app.js 传递到 index.html? 我可以传递静态文本,但需要传递计算的数字或数组中的数字

[英]How to pass a number from app.js to index.html? I can pass a static text, but need to pass a calculated number or number from an array

How to pass a number from app.js to index.html?如何将一个数字从 app.js 传递到 index.html? I can pass a static text, but need to pass a calculated number or number from an array.我可以传递静态文本,但需要传递一个计算出的数字或数组中的数字。 This is my code that works for passing a static string.这是我用于传递静态字符串的代码。

``d3.select("li").text("score") ``d3.select("li").text("score")

It successfully updates the desired 'li' tag of my html, and displays 'score' without quotes on the webpage.它成功地更新了我的 html 所需的 'li' 标签,并在网页上显示不带引号的 'score'。

But I do not know how to modify the code to instead of 'score', display a number that is calculated inside my javascript code (app.js).但我不知道如何修改代码而不是“分数”,显示在我的 javascript 代码(app.js)中计算的数字。 Or alternatively how to modify the code to pass a number from an array inside app.js to the html.或者如何修改代码以将一个数字从 app.js 中的数组传递到 html。 Please help.请帮忙。 Thank you.谢谢你。

You can set anything as text parameter.您可以将任何内容设置为文本参数。 It should display correctly without any problem.它应该正确显示,没有任何问题。

function updateScore(){
    let computedValue = Math.random();
    d3.select("li").text(computedValue);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM