JavaScript在代码中显示var [英] Javascript displaying a var in code
本文介绍了JavaScript在代码中显示var的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
function test()
{
var first = document.getElementById('first')。value; // value == hello
var second = document.getElementById(second)。value; // value == bye
var third = document.getElementById(third)。value; //值==疯狂
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;
应该会更好。
I want the value of some vars to be shown in the string.
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> ";
I want the string to display:
<script>
var firstValue = " hello ";
var secondValue = " bye ";
var thirdValue = " crazy ";
var forthValue = " night ";
</script> ";
解决方案
variables names in javascript can't start with a number.
So change your variable names.
var name1 = document.getElementById('1').value;
should be better.
这篇关于JavaScript在代码中显示var的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文