1. htm和html:javascript
靜態網頁,經過固定標籤實現css
1 <!-- 2 To change this template, choose Tools | Templates 3 and open the template in the editor. 4 --> 5 <!DOCTYPE html> 6 <html> 7 <head> 8 <title>第一個javaScript程序</title> 9 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 10 <script language="JavaScript"><!-- 使用javascript語言 --> 11 alert("Hello World!"); //彈出警告框 12 alert("Hello SCUT!"); 13 </script> 14 15 <script language="javascript" src="hello.js"> 16 </script> 17 18 <script language="javascript"> 19 document.write("<h1>hello World!!!</h1>"); 20 document.write("<h5>www.scut.edn.cn</h5>"); 21 </script> 22 </head> 23 <body> 24 <h1>這是一個網頁~~~</h1> 25 <script language="JavaScript"> 26 alert("第3個警告框!"); 27 </script> 28 </body> 29 </html>
2. js:javascripthtml
標籤:java
<script language="text/javascript">node
function fun(){web
}app
</script>dom
1 <!-- 2 To change this template, choose Tools | Templates 3 and open the template in the editor. 4 --> 5 <!DOCTYPE html> 6 <html> 7 <head> 8 <title>這是js裏關於變量var的學習</title> 9 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 10 <script language="javascript"> 11 12 var num = 30; //定義一個數字 13 var info = "www.scut.edu.cn";//定義一個字符串 14 alert("數字:" + num + ";字符串:" + info); 15 16 str = "scut"; 17 if (str === "scut") 18 alert("str符合if判斷!"); 19 else 20 alert("str不符合if判斷!"); 21 22 </script> 23 24 <!-- 使用循環輸入5行10列的表格 --> 25 <script language="javascript"> 26 var row = 5; 27 var col = 10; 28 document.write("<table border=\"1\">");// 輸出表格 29 for (i = 0; i < row; i++) { 30 document.write("<tr>"); 31 for (j = 0; j < col; j++) { 32 document.write("<td>" + i * j + "</td>"); 33 } 34 document.write("</tr>"); 35 } 36 document.write("</table>"); 37 </script> 38 39 40 <!--輸出九九乘法表 --> 41 <script language="javascript"> 42 document.write("<table border=\"1\">"); 43 for (i = 1; i <= 9; i++) { 44 document.write("<tr>"); 45 for (j = 1; j <= 9; j++) { 46 if (j <= i) { 47 document.write("<td>" + i + "*" + j + "=" + i * j + "</td>"); 48 } 49 else { 50 document.write("<td> </td>"); 51 } 52 } 53 document.write("</tr>"); 54 } 55 document.write("</table>"); 56 </script> 57 58 </head> 59 <body> 60 </body> 61 </html>
3. xml 可拓展的標記性語言ide
<name>周mm</name>學習
1 <?xml version="1.0" encoding="GB2312"?> 2 <!-- 3 To change this template, choose Tools | Templates 4 and open the template in the editor. 5 --> 6 <addresslist> 7 <linkman> 8 <name>周敏麗</name> 9 <email>1234567@163.com</email> 10 </linkman> 11 <linkman> 12 <name>葉子君</name> 13 <email>7654321@163.com</email> 14 </linkman> 15 </addresslist>
(1)xml解析: DOM解析,SAX解析
1 /* 2 * To change this template, choose Tools | Templates 3 * and open the template in the editor. 4 */ 5 package xmlpackage; 6 7 /** 8 * 9 * @author XiaoTianCai 10 */ 11 /* 12 * DOM解析xml文件內容 13 */ 14 15 import java.io.IOException; 16 import javax.xml.parsers.DocumentBuilder; 17 import javax.xml.parsers.DocumentBuilderFactory; 18 import javax.xml.parsers.ParserConfigurationException; 19 import org.xml.sax.SAXException; 20 import org.w3c.dom.Document; 21 import org.w3c.dom.Element; 22 import org.w3c.dom.NodeList; 23 24 public class DOMdemo_test02 { 25 26 public static void main(String[] args) { 27 //(1)創建DocumentBuilderFactory,以用於取得DocumentBuilder 28 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 29 //(2)經過DocumentBuilderFactory取得DocumentBuilder 30 DocumentBuilder builder = null; 31 try { 32 builder = factory.newDocumentBuilder(); 33 } catch (ParserConfigurationException e) { 34 e.printStackTrace(); 35 } 36 37 //(3)定義Document接口對象,經過DocumentBuilder類進行DOM樹的轉換操做 38 Document doc = null; 39 try { 40 doc = builder.parse("web\\xml_test.xml"); 41 } catch (SAXException | IOException e) { 42 e.printStackTrace(); 43 } 44 //(4)查找linkman的節點 45 NodeList nl = doc.getElementsByTagName("linkman"); 46 //(5)輸出nodelist中的第一個節點張文本節點的內容 47 for (int i = 0; i < nl.getLength(); i++) { //循環輸出節點內容 48 Element e = (Element) nl.item(i); //取得第一個元素 49 System.out.println("姓名:" + e.getElementsByTagName("name").item(0).getFirstChild().getNodeValue()); 50 System.out.println("郵箱:" + e.getElementsByTagName("email").item(0).getFirstChild().getNodeValue()); 51 } 52 } 53 }
(2)生成xml文檔並保存爲磁盤文件:
1 /* 2 * To change this template, choose Tools | Templates 3 * and open the template in the editor. 4 */ 5 package xmlpackage; 6 7 /** 8 * @author XiaoTianCai 9 */ 10 /* 11 * 生成xml文件並輸出到磁盤文件中, 12 * xml文件不會格式整齊,但實際使用中格式沒有任何關係 13 */ 14 import java.io.File; 15 import java.io.IOException; 16 import javax.xml.parsers.DocumentBuilder; 17 import javax.xml.parsers.DocumentBuilderFactory; 18 import javax.xml.parsers.ParserConfigurationException; 19 import javax.xml.transform.OutputKeys; 20 import javax.xml.transform.Transformer; 21 import javax.xml.transform.TransformerConfigurationException; 22 import javax.xml.transform.TransformerException; 23 import javax.xml.transform.TransformerFactory; 24 import javax.xml.transform.dom.DOMSource; 25 import javax.xml.transform.stream.StreamResult; 26 import org.xml.sax.SAXException; 27 import org.w3c.dom.Document; 28 import org.w3c.dom.Element; 29 import org.w3c.dom.NodeList; 30 31 public class DOMdemo_build_xml_test { 32 33 public static void main(String[] args) { 34 //(1)創建DocumentBuilderFactory,用於取得DocumentBuilder 35 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 36 //(2)經過DocumentBuilderFactory,取得DocumentBuilder 37 DocumentBuilder builder = null; 38 try { 39 builder = factory.newDocumentBuilder(); 40 } catch (ParserConfigurationException e) { 41 e.printStackTrace(); 42 } 43 //(3)定義Document接口對象,經過DocumentBuilder類進行DOM樹的轉換操做 44 Document doc = null; 45 doc = builder.newDocument(); //建立一個新文檔 46 //(4)創建各個操做節點 47 Element addresslist = doc.createElement("addresslist");//創建節點 48 Element linkman = doc.createElement("linkman"); 49 Element name = doc.createElement("name"); 50 Element email = doc.createElement("email"); 51 //(5)設置節點的文本內容,即爲每個節點添加文本節點 52 name.appendChild(doc.createTextNode("周敏麗"));//設置文本 53 email.appendChild(doc.createTextNode("1234567@163.com")); 54 //(6)設置節點關係 55 linkman.appendChild(name); //子節點 56 linkman.appendChild(email); 57 addresslist.appendChild(linkman); 58 doc.appendChild(addresslist); //文本上的保存節點 59 //(7)將文檔輸出到文件中 60 TransformerFactory tf = TransformerFactory.newInstance(); 61 Transformer t = null; 62 try { 63 t = tf.newTransformer(); 64 } catch (TransformerConfigurationException e1) { 65 e1.printStackTrace(); 66 } 67 t.setOutputProperty(OutputKeys.ENCODING, "GB2312"); //設置編碼 68 DOMSource source = new DOMSource(doc); //輸出文檔 69 StreamResult result = new StreamResult(new File("web\\output.xml")); //指定輸出位置 70 try { 71 t.transform(source, result); 72 } catch (TransformerException e) { 73 e.printStackTrace(); 74 } 75 } 76 }
(3)xml文件顯示:一般加載css層疊樣式表
1 /* 2 Document : attrib 3 Created on : 2013-7-15, 21:21:22 4 Author : XiaoTianCai 5 Description: 6 Purpose of the stylesheet follows. 7 */ 8 name 9 { 10 display: block; 11 color: blue; 12 font-size: 20pt; 13 font-weight: bold; 14 } 15 id,conpany,email,tel,site 16 { 17 display: block; 18 color: black; 19 font-size: 14pt; 20 font-weight: normal; 21 font-style: italic; 22 }
1 <?xml version="1.0" encoding="GB2312" standalone="no"?> 2 <!-- 3 To change this template, choose Tools | Templates 4 and open the template in the editor. 5 --> 6 <?xml-stylesheet type="text/css" href="attrib.css"?> <!--引入css樣式表--> 7 <addresslist> 8 <linkman> 9 <name>周mm</name> 10 <id>0001</id> 11 <company>廣二師</company> 12 <email>nmnmll@qq.com</email> 13 <tel>020-1124568</tel> 14 <site>www.zhiaiyaya.com</site> 15 </linkman> 16 </addresslist>