-
文檔對象模型DOM(Document Object Model)定義訪問和處理HTML文檔的標(biāo)準(zhǔn)方法。DOM?將HTML文檔呈現(xiàn)為帶有元素、屬性和文本的樹結(jié)構(gòu)(節(jié)點樹)。
HTML文檔可以說由節(jié)點構(gòu)成的集合,三種常見的DOM節(jié)點:
1. 元素節(jié)點:上圖中<html>、<body>、<p>等都是元素節(jié)點,即標(biāo)簽。
2. 文本節(jié)點:向用戶展示的內(nèi)容,如<li>...</li>中的JavaScript、DOM、CSS等文本。
3. 屬性節(jié)點:元素屬性,如<a>標(biāo)簽的鏈接屬性href="http://idcbgp.cn"。
查看全部 -
JavaScript-輸出內(nèi)容(document.write())
JavaScript-警告(alert()消息對話框)
JavaScript-確認(confirm() 消息對話框)
JavaScript-提問(prompt()消息對話框)
JavaScript-打開新窗口(window.open())
JavaScript-關(guān)閉窗口(window.close())
查看全部 -
var m1 = confirm("是否打開新窗口?");
? ? if(m1=true){
? ? ? ? prompt("打開網(wǎng)址","http://idcbgp.cn/");
? ? ? ? window.open('http://idcbgp.cn/','_blank',width=400,height=500);
? ? }else{
? ? ? ??
? ? }
查看全部 -
confirm 消息對話框通常用于允許用戶做選擇的動作,如:“你對嗎?”等。彈出對話框(包括一個確定按鈕和一個取消按鈕)。
語法:
confirm(str);
參數(shù)說明:
str:在消息對話框中要顯示的文本返回值: Boolean值
返回值:
當(dāng)用戶點擊"確定"按鈕時,返回true
當(dāng)用戶點擊"取消"按鈕時,返回false查看全部 -
? ? 1.變量必須使用字母、下劃線(_)或者美元符($)開始。
? ? 2.然后可以使用任意多個英文字母、數(shù)字、下劃線(_)或者美元符($)組成。
? ? 3.不能使用JavaScript關(guān)鍵詞與JavaScript保留字。
查看全部 -
注意:?javascript作為一種腳本語言可以放在html頁面中任何位置,但是瀏覽器解釋html時是按先后順序的,所以前面的script就先被執(zhí)行。比如進行頁面顯示初始化的js必須放在head里面,因為初始化都要求提前進行(如給頁面body設(shè)置css等);而如果是通過事件調(diào)用執(zhí)行的function那么對位置沒什么要求的。
查看全部 -
<!DOCTYPE html>
<html>
?<head>
? <title> new document </title>??
? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>? ?
? <script type="text/javascript">??
? ? function openWindow(){
? ? ? ? var a=confirm("是否要打開?");
? ? ? ? if(a=true){
? ? ? ? ? ? var b=prompt("確定打開的網(wǎng)址:","http://idcbgp.cn/");
? ? ? ? ? ? if(b!=null){
? ? ? ? ? ? ? ? window.open(b,'_blank','width=400px','height=500px','menubar=no','toolbar=no');
? ? ? ? ? ? }
? ? ? ? ? ? else{
? ? ? ? ? ? ? ? document.write("請重新輸入網(wǎng)址!");
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? else(){
? ? ? ? ? ? document.write("不打開!");
? ? ? ? }
? ? }
? ? // 新窗口打開時彈出確認框,是否打開
? ? // 通過輸入對話框,確定打開的網(wǎng)址,默認為 http://idcbgp.cn/
? ? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
? ??
? ??
? </script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開網(wǎng)站" onclick="openWindow()" />?
?</body>
</html>
查看全部 -
<!DOCTYPE html>
<html>
?<head>
? <title> new document </title>??
? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>? ?
? <script type="text/javascript">??
? ? function openWindow(){
? ? ? ? var a=confirm("是否打開指定網(wǎng)頁?");
? ? if (a==true)
? ? { var y=prompt("請輸入要打開的網(wǎng)頁:","http://idcbgp.cn/");
? ? ? ? if (y!=null)
? ? ? ? {? ?window.open(y,'width=400px','height=500px','menubar=no','toolbar=no');}
? ? ? ? else
? ? ? ? {? document.write("請重新輸入!");}
? ? }
? ? else
? ? {? ?document.write("不打開!")}}
? ? // 新窗口打開時彈出確認框,是否打開
? ? // 通過輸入對話框,確定打開的網(wǎng)址,默認為 http://idcbgp.cn/
? ? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
? ??
? ??
? </script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開網(wǎng)站" onclick="openWindow()" />?
?</body>
</html>
查看全部 -
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" Content="text/html; charset=utf-8" />
<title>javascript</title>
<style type="text/css">
body{font-size:12px;}
#txt{
? ? height:400px;
? ? width:600px;
border:#333 solid 1px;
padding:5px;
color:black;
}
p{
line-height:18px;
text-indent:2em;}
</style>
</head>
<body>
? <h2 id="con">JavaScript課程</h2>
? <div id="txt">?
? ? ?<h5>JavaScript為網(wǎng)頁添加動態(tài)效果并實現(xiàn)與用戶交互的功能。</h5>
? ? ? ? <p>1. JavaScript入門篇,讓不懂JS的你,快速了解JS。</p>
? ? ? ? <p>2. JavaScript進階篇,讓你掌握JS的基礎(chǔ)語法、函數(shù)、數(shù)組、事件、內(nèi)置對象、BOM瀏覽器、DOM操作。</p>
? ? ? ? <p>3. 學(xué)完以上兩門基礎(chǔ)課后,在深入學(xué)習(xí)JavaScript的變量作用域、事件、對象、運動、cookie、正則表達式、ajax等課程。</p>
? </div>
? <form>
? <!--當(dāng)點擊相應(yīng)按鈕,執(zhí)行相應(yīng)操作,為按鈕添加相應(yīng)事件-->
? ? <input type="button" value="改變顏色" onclick="a()">??
? ? <input type="button" value="改變寬高" onclick="b()">
? ? <input type="button" value="隱藏內(nèi)容" onclick="c()">
? ? <input type="button" value="顯示內(nèi)容" onclick="d()">
? ? <input type="button" value="取消設(shè)置" onclick="e()">
? </form>
? <script type="text/javascript">
//定義"改變顏色"的函數(shù)
? ? var achar=document.getElementById("txt");
? ? function a(){
? ? ? ? achar.style.color="blue";
? ? }
//定義"改變寬高"的函數(shù)
? ? var bchar=document.getElementById("txt");
? ? function b(){
? ? ? ? bchar.style.width="200px";
? ? ? ? bchar.style.height="300px";
? ? }
//定義"隱藏內(nèi)容"的函數(shù)
? ? var cchar=document.getElementById("txt");
? ? function c(){
? ? ? ? cchar.style.display="none";
? ? }
//定義"顯示內(nèi)容"的函數(shù)
? ? var dchar=document.getElementById("txt");
? ? function d(){
? ? ? ? dchar.style.display="block";
? ? }
//定義"取消設(shè)置"的函數(shù)
? ?
? ? var echar=document.getElementById("txt");
? ? function e(){
? ? ? ? var econ=confirm("要取消設(shè)置嗎?");
? ? ? ? if (econ==true){
? ? ? ? ? ? echar.style.height="400px";
? ? ? ? ? ? echar.style.width="600px";
? ? ? ? ? ? echar.style.display="block";
? ? ? ? ? ? echar.style.color="black";
? ? ? ? }
? ? ? ? else {}
? ? }
? </script>
</body>
</html>
查看全部 -
?function openWindow(){
? ? ? ? var a=confirm("是否打開指定網(wǎng)頁?");
? ? if (a==true)
? ? { var y=prompt("請輸入要打開的網(wǎng)頁:","http://idcbgp.cn/");
? ? ? ? if (y!=null)
? ? ? ? {? ?window.open(y,'width=400px','height=500px','menubar=no','toolbar=no');}
? ? ? ? else
? ? ? ? {? document.write("請重新輸入!");}
? ? }
? ? else
? ? {? ?document.write("不打開!")}}
查看全部 -
//
/*
*/
查看全部 -
function openWindow(){
? ? ? ? var myconfir = confirm("是否打開網(wǎng)站?");
? ? ? ? if ( myconfir==true){
? ? ? ? ? ? var myweb=prompt('請輸入要打開的網(wǎng)站地址');
? ? ? ? ? ? if (myweb==null){
? ? ? ? ? ? ? ?alert("再見")
? ? ? ? ? ? }
? ? ? ? ? ? else if(myweb=="") {
? ? ? ? ? ? ? ?window.open('http://idcbgp.cn/', '_blank', 'width=400,height=500,menubar=no,toolbar=no')
? ? ? ? ? ? }
? ? ? ? ? ? else{
? ? ? ? ? ? ? ? window.open(myweb, '_blank', 'width=400,height=500,menubar=no,toolbar=no')?
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? else{
? ? ? ? ? ? alert("再見")
? ? ? ? ? ??
? ? ? ? }
? ? }
查看全部 -
1.document.write("");(直接輸出內(nèi)容)
2.document.write(變量名);(輸出變量里的內(nèi)容)
3.document.write(變量名+"");(多項內(nèi)容的輸出通過+號連接)
4.document.write(變量名+""+"<br>"); (輸出HTML標(biāo)簽,并起作用,標(biāo)簽使用“”括起來)查看全部 -
用function定義一個函數(shù):
function +函數(shù)名(){ ?函數(shù)代碼(完成特定功能的代碼); ?}
然后在form 里面用 < input type="button" ?value="按鈕名稱" onclick="函數(shù)名()" / >
執(zhí)行input type="button"?
創(chuàng)建一個按鈕value="按鈕顯示文本"
onclick="函數(shù)名()" 執(zhí)行該函數(shù)
查看全部 -
這段代碼執(zhí)行后,p標(biāo)簽內(nèi)容顯示在瀏覽器里時,就是已經(jīng)通過對象innerHTML修改之后的內(nèi)容,這里有一個執(zhí)行順序的問題,p標(biāo)簽內(nèi)容在修改前沒有顯示,但是js腳本的代碼在p標(biāo)簽下方,確認一下
查看全部
舉報