當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JS入门(一)
最近在 mooc 學習了點 JS 的內容,也僅僅只是入門。。。
<!-- JS入門 --><!-- 引用JS文件 --> <script src="script.js"></script><!-- 輸出內容 --> var mystr="hello"; document.write(mystr+"I love JavaScript");<!-- 彈窗警告 --> var mychar="I love JavaScript"; alert(mychar);<!-- 選擇對話框 --> <!-- return ture or false --> confirm("你是男生?");<!-- 提問對話框 --> <!-- str1: 要顯示在消息對話框中的文本,不可修改 --> <!-- str2:文本框中的內容,可以修改 --> prompt("str1","str2");<!-- 打開窗口 --> <!-- window.open([url],[name],[str]); --> <!-- _blank:在新窗口顯示目標網頁 --> <!-- _self:在當前窗口顯示目標網頁 --> <!-- _top:框架網頁中在上部窗口中顯示目標網頁 --> window.open('http://www.imooc.com','_blank','width=600,height=400,top=100,left=0');<!-- 關閉當前窗口 --> window.close(); <!-- 關閉特定對象的窗口 --> class.close();<!-- 通過Id獲取元素 --> document.getElementById("con");<!-- innerHTML屬性用于獲取或替換 HTML 元素的內容。 --> document.getElementById.innerHTML="new content";<!-- Object.style.用于改變HTML樣式 --> document.getElementById("con").style.color="red";<!-- Object.style.display用于隱藏或顯示的效果 --> <!-- 隱藏內容 --> document.getElementById("con").style.display="none"; <!-- 顯示內容 --> document.getElementById("con").style.display="block";<!-- className屬性設置或返回元素的class 屬性 --> <!-- 獲取元素的class 屬性 --> <!-- 為網頁內的某個元素指定一個css樣式來更改該元素的外觀 --> <style>body{ font-size:16px;}.one{border:1px solid #eee;width:230px;height:50px;background:#ccc;color:red;}.two{border:1px solid #ccc;width:230px;height:50px;background:#9CF;color:blue;} </style> <!-- 改變外觀 --> document.getElementById("p1").className="one";<!-- 編程挑戰 --> <!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;} p{line-height:18px;text-indent:2em;} </style> </head> <body><h2 id="con">JavaScript課程</H2><div id="txt"> <h5>JavaScript為網頁添加動態效果并實現與用戶交互的功能。</h5><p>1. JavaScript入門篇,讓不懂JS的你,快速了解JS。</p><p>2. JavaScript進階篇,讓你掌握JS的基礎語法、函數、數組、事件、內置對象、BOM瀏覽器、DOM操作。</p><p>3. 學完以上兩門基礎課后,在深入學習JavaScript的變量作用域、事件、對象、運動、cookie、正則表達式、ajax等課程。</p></div><form><!--當點擊相應按鈕,執行相應操作,為按鈕添加相應事件--><input type="button" value="改變顏色" onclick="changecolor()"> <input type="button" value="改變寬高" onclick="changewh()"><input type="button" value="隱藏內容" onclick="none()"><input type="button" value="顯示內容" onclick="block()"><input type="button" value="取消設置" onclick="nonono()"></form><script type="text/javascript"> //定義"改變顏色"的函數function changecolor(){document.getElementById("txt").style.color="blue";document.getElementById("txt").style.backgroundColor="red";}//定義"改變寬高"的函數function changewh(){document.getElementById("txt").style.width="300px";document.getElementById("txt").style.height="300px";}//定義"隱藏內容"的函數function none(){document.getElementById("txt").style.display="none";}//定義"顯示內容"的函數function bolck(){document.getElementById("txt").style.display="block";}//定義"取消設置"的函數function nonono(){if(confirm("是否取消設置?")){document.getElementById("txt").removeAttribute('style');}}</script> </body> </html>?
轉載于:https://www.cnblogs.com/ygdblogs/p/5428359.html
總結
- 上一篇: STL之deque详解
- 下一篇: Spring与Quartz的整合实现定时