javascript中輸出資訊的方法-資訊確認框-提示輸入框-文檔流輸出,javascript輸入框
js中輸出資訊的方法
1、文檔流輸出
document.write('hello');
2、輸出資訊氣球 模態對話方塊
window.alert('要輸出顯示的內容'); 或 alert('要輸出顯示的內容');
alert(n);
3、資訊確認框
var f = window.confirm('是否要進入新浪網'); confirm("");
if(f){
location.href = 'http://www.sina.com.cn';
}
4、提示輸入框
window.prompt
var n = window.prompt('請輸入年齡',18);
if(n>=18){
document.write('歡迎你年輕人');
}
5、控制標籤,在標籤上直接輸出,
通過document.getElementById('id') 找到對象標籤,可以直接控制裡邊的值,進行輸出
setInterval(function(){document.getElementById('ttt').innerHTML = "目前時間:"+new Date().toLocaleString();},1000);
<script>
document.getElementById('uname').value = "佚名";
</script>
6、把資訊直接輸出到標題
document.title = "hello";
javascript訊息提示框代碼我突然忘記了代碼大概是這樣的:javascript('這個是提示框內容')
<script type="text/javascript">
alert("這個是提示框內容")
</script>
大家幫我看看這段javascript代碼為何讀取不到輸入框的內容?
document.getElementsByName方法,看名字就知道:Elements是複數,得到的是個數組!
單個標記的訪問最好用getElementByID
一般,name用在伺服器指令碼上,ID多用在客戶指令碼