gpt4 book ai didi

Javascript 在代码中显示 var

转载 作者:行者123 更新时间:2023-11-28 20:03:46 25 4
gpt4 key购买 nike

我希望某些变量的值显示在字符串中。

 function test()
{
var first = document.getElementById('first').value; //value ==hello
var second = document.getElementById("second").value; //value == bye
var third = document.getElementById("third").value; //value == crazy
var forth = document.getElementById("forth").value; // value == night


var myString = " \
<script> \
var firstValue = "\" + first + \""; \
var secondValue = "\" + second + \""; \
var thirdValue = "\" +third + \""; \
var forthValue = "\" +forth + \""; \
<\/script> ";

我想要显示字符串:

 <script> 
var firstValue = " hello ";
var secondValue = " bye ";
var thirdValue = " crazy ";
var forthValue = " night ";
</script> ";

最佳答案

JavaScript 中的变量名称不能以数字开头。

所以更改你的变量名称。

var name1  = document.getElementById('1').value;

应该会更好。

关于Javascript 在代码中显示 var,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21192488/

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