我是 Javascript 的新手并试图调试一个简单的 js 函数。我需要通过警报语句获取 x 的值,但它不能正确显示。如何在这种情况下连接字符串和 int 。
<html>
<head>
</head>
<body>
<script>
function displaydate()
{
document.getElementById("test").innerHTML='first line changed';
document.getElementById("test1").innerHTML='second line changed';
var x = 5;
alert("Value of x" + String.valueOf(x));
}
</script>
<p id="test">this is the 1st line</p>
<p id="test1">this is the 2nd line</p>
<button type="button" onclick="displaydate()">clickme!</button>
<body>
</html>
新代码:
<html>
<head>
</head>
<body>
<script>
function displaydate()
{
document.getElementById("test").innerHTML='first line changed';
document.getElementById("test1").innerHTML='second line changed';
var x = 5;
alert("Value of x=" + x);
var cars=new Array();
cars[0]='car';
cars[1]='Volvo';
alert("Value of arrary 1 var=' + cars[0]);
//alert("Value of arrary 2 var='+cars[1]);
}
</script>
<p id="test">this is the 1st line</p>
<p id="test1">this is the 2nd line</p>
<button type="button" onclick="displaydate()">clickme!</button>
<body>
</html>