請大神看看 我想通過JavaScript給text控件賦值當前的日期,但都沒有顯示出來,
請大神指出問題在哪 代碼如下:
<script type="text/javascript">
function showdata() {
var currentTime = new Date();
var year = currentTime.getFullYear();
var month = currentTime.getMonth();
var day = currentTime.getDate();
var str = year + "." + month + "." + day;
document.getElementById("Text1").innerText = str;
</script>
-------------------------------------------------------------------------------------<tr>
<td id="newscell" class="style2" align="center" onmouseover="changebgcolor()" onmouseout="leftmouse()"><a href="Default2.aspx">新聞</a>
</td>
<td id="hunancell" class="style3" align="center" onmouseout="lefthunancellmouse()" onmouseover="changehunancolor()"><a href="Default.aspx">看湖南</a>
</td>
<td class="style1"><input type="text" id="Text1" onload="showdata()"/>
</td>
</tr>
--------------------------------------------------------------------------------------
document.getElementById("Text1").innerText = str; 這一句改成 .
document.getElementById("Text1").innerHtml= str;
document.getElementById("Text1").value= str; 都沒有效果
input沒有onload事件,而且你函數也有問題,沒有閉合,設置輸入控件內容用value屬性
function showdata() {
var currentTime = new Date();
var year = currentTime.getFullYear();
var month = currentTime.getMonth();
var day = currentTime.getDate();
var str = year + "." + month + "." + day;
document.getElementById("Text1").value = str;///////
}
window.onload=showdata///////////////