JavaScript中的变量怎么显示到HTML中去
<script language= "javascript ">
<!--
var enabled = 0; today = new Date(); var date;
date = (today.getYear()) + "年 " + (today.getMonth() + 1 ) + "月 " + today.getDate() + "日 " ;
document.write(date );
// -->
</script>
我想把date的值在html中
<table>
<tr>
<td>
2007年1月12日
</td>
</tr>
</table>
<td> </td> 中输出,应该怎么办,高手指点下!!
------解决方案-------------------- <script language= "javascript ">
<!--
var enabled = 0; today = new Date(); var date;
date = (today.getYear()) + "年 " + (today.getMonth() + 1 ) + "月 " + today.getDate() + "日 " ;
var s = document.getElementsByID( "showDate ");
s.innerHTML = date;
// -->
</script>
我想把date的值在html中
<table>
<tr>
<td>
<div id= "showDate "> </div>
</td>
</tr>
</table>
------解决方案--------------------innerText
------解决方案--------------------其实哪个div还可以动态生成的。
<html>
<head>
<title> test </title>
</head>
<body>
<script language= "javascript ">
var enabled = 0; today = new Date(); var date;
date = (today.getYear()) + "年 " + (today.getMonth() + 1 ) + "月 " + today.getDate() + "日 " ;
var div = document.createElement( 'div ');
div.innerText = date;
document.body.appendChild(document.createElement( 'table ').appendChild(document.createElement( 'tr ').appendChild
(document.createElement( 'td ').appendChild(div))));
</script>
</body>
</html>
------解决方案-------------------- <script language= "javascript ">
<!--
var enabled = 0; today = new Date(); var date;
date = (today.getYear()) + "年 " + (today.getMonth() + 1 ) + "月 " + today.getDate() + "日 " ;
// -->
</script>
我想把date的值在html中
<table>
<tr>
<td>
2007年1月12日
</td>
</tr>
</table>
<td>
<script>
document.write(date);
</script>
</td>