a
+
b
,
c
+
d
,
e
+
f
...
y
+
z
逗號表達式允許一條語句中執(zhí)行多個表達式,例如
var
a
=
5
,
b
=
6
,
c
=
7
,
a
=
b
+
c
,
c
=
a
+
b
;
上面并非優(yōu)美的語句,因為賦值表達式與加法表達式同時在一個逗號表達式中,容易產(chǎn)生混亂。最好把單一功能的表達式合并。
var
a
=
5
,
b
=
6
,
c
=
7
;
a
=
b
+
c
,
c
=
a
+
b
;
有些時候你精通一門語言,但是會發(fā)現(xiàn)你其實整天在和其它語言打交道,也許你以為這些微不足道,不至于影響你的開發(fā)進度,但恰恰是這些你不重視的東西會浪費你很多時間,我一直以為我早在幾年前就已經(jīng)精通JavaScript了,直到目前,我才越來越覺得JavaScript遠比我想象的復雜和強大,我開始崇拜它,就像崇拜所有OOP語言一樣~
趁著節(jié)日的空隙,把有關JavaScript的方法和技巧整理下,讓每個在為JavaScript而煩惱的人明白,JavaScript就這么回事!并希望JavaScript還可以成為你的朋友,讓你豁然開朗,在項目中更好的應用~
適合閱讀范圍:對JavaScript一無所知~離精通只差一步之遙的人
基礎知識:HTML
JavaScript就這么回事:基礎知識
1 創(chuàng)建腳本塊
<script language="JavaScript">
JavaScript code goes here
</script>
2 隱藏腳本代碼
1 <script language="JavaScript">
2 <!--
3 document.write("Hello");
4 // -->
5 </script>
在不支持JavaScript的瀏覽器中將不執(zhí)行相關代碼
3 瀏覽器不支持的時候顯示
1 <noscript>
2 Hello to the non-JavaScript browser.
3 </noscript>
4 鏈接外部腳本文件
1 <script language="JavaScript" src="filename.js"></script>
5 注釋腳本
1 // This is a comment
2 document.write("Hello"); // This is a comment
3 /*
4 All of this
5 is a comment
6 */
6 輸出到瀏覽器
1 document.write("<strong>Hello</strong>");
7 定義變量
1 var myVariable = "some value";
8 字符串相加
1 var myString = "String1" + "String2";
9 字符串搜索
1 <script language="JavaScript">
2 <!--
3 var myVariable = "Hello there";
4 var therePlace = myVariable.search("there");
5 document.write(therePlace);
6 // -->
7 </script>
10 字符串替換
1 thisVar.replace("Monday","Friday");
11 格式化字串
01 <script language="JavaScript">
02 <!--
03 var myVariable = 'Hello there";
04 document.write(myVariable.big() + "<br>");
05 document.write(myVariable.blink() + "<br>");
06 document.write(myVariable.bold() + "<br>");
07 document.write(myVariable.fixed() + "<br>");
08 document.write(myVariable.fontcolor("red") + "<br>");
09 document.write(myVariable.fontsize("18pt") + "<br>");
10 document.write(myVariable.italics() + "<br>");
11 document.write(myVariable.small() + "<br>");
12 document.write(myVariable.strike() + "<br>");
13 document.write(myVariable.sub() + "<br>");
14 document.write(myVariable.sup() + "<br>");
15 document.write(myVariable.toLowerCase() + "<br>");
16 document.write(myVariable.toUpperCase() + "<br>");
17 var firstString = "My String";
18 var finalString = firstString.bold().toLowerCase().fontcolor("red");
19 // -->
20 </script>
12 創(chuàng)建數(shù)組
01 <script language="JavaScript">
02 <!--
03 var myArray = new Array(5);
04 myArray[0] = "First Entry";
05 myArray[1] = "Second Entry";
06 myArray[2] = "Third Entry";
07 myArray[3] = "Fourth Entry";
08 myArray[4] = "Fifth Entry";
09 var anotherArray = new Array("First Entry","Second Entry","Third Entry","Fourth Entry","Fifth Entry");
10 // -->
11 </script>
13 數(shù)組排序
01 <script language="JavaScript">
02 <!--
03 var myArray = new Array(5);
04 myArray[0] = "z";
05 myArray[1] = "c";
06 myArray[2] = "d";
07 myArray[3] = "a";
08 myArray[4] = "q";
09 document.write(myArray.sort());
10 // -->
11 </script>
14 分割字符串
01 <script language="JavaScript">
02 <!--
03 var myVariable = "a,b,c,d";
04 var stringArray = myVariable.split(",");
05 document.write(stringArray[0]);
06 document.write(stringArray[1]);
07 document.write(stringArray[2]);
08 document.write(stringArray[3]);
09 // -->
10 </script>
15 彈出警告信息
1 <script language="JavaScript">
2 <!--
3 window.alert("Hello");
4 // -->
5 </script>
16 彈出確認框
1 <script language="JavaScript">
2 <!--
3 var result = window.confirm("Click OK to continue");
4 // -->
5 </script>
17 定義函數(shù)
1 <script language="JavaScript">
2 <!--
3 function multiple(number1,number2) {
4 var result = number1 * number2;
5 return result;
6 }
7 // -->
8 </script>
18 調用JS函數(shù)
1 <a href="#" onClick="functionName()">Link text</a>
2 <a >Link text</a>
19 在頁面加載完成后執(zhí)行函數(shù)
1 <body onLoad="functionName();">
2 Body of the page
3 </body>
20 條件判斷
1 <script>
2 <!--
3 var userChoice = window.confirm("Choose OK or Cancel");
4 var result = (userChoice == true) ? "OK" : "Cancel";
5 document.write(result);
6 // -->
7 </script>
21 指定次數(shù)循環(huán)
01 <script>
02 <!--
03 var myArray = new Array(3);
04 myArray[0] = "Item 0";
05 myArray[1] = "Item 1";
06 myArray[2] = "Item 2";
07 for (i = 0; i < myArray.length; i++) {
08 document.write(myArray[i] + "<br>");
09 }
10 // -->
11 </script>
22 設定將來執(zhí)行
1 <script>
2 <!--
3 function hello() {
4 window.alert("Hello");
5 }
6 window.setTimeout("hello()",5000);
7 // -->
8 </script>
23 定時執(zhí)行函數(shù)
1 <script>
2 <!--
3 function hello() {
4 window.alert("Hello");
5 window.setTimeout("hello()",5000);
6 }
7 window.setTimeout("hello()",5000);
8 // -->
9 </script>
24 取消定時執(zhí)行
1 <script>
2 <!--
3 function hello() {
4 window.alert("Hello");
5 }
6 var myTimeout = window.setTimeout("hello()",5000);
7 window.clearTimeout(myTimeout);
8 // -->
9 </script>
1.引入 jQuery 文件和 prettify.js 文件
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.min.js"></script> <script src="prettify.js"type="text/javascript"></script> <link href="/prettify.css" type="text/css" rel="stylesheet" />2.調用 prettify.js 實現(xiàn)代碼高亮
<body onload="prettyPrint()"> </body>將你需要高亮顯示的代碼片斷放在 pre標記里,如下:
<pre class="prettyprint"> @*你的代碼片斷*@ </pre>
event.clientX 返回最后一次點擊鼠標X坐標值;event.clientY 返回最后一次點擊鼠標Y坐標值;event.offsetX 返回當前鼠標懸停X坐標值event.offsetY 返回當前鼠標懸停Y坐標值
document.write(document.lastModified) 網(wǎng)頁最后一次更新時間document.ondblclick=x 當雙擊鼠標產(chǎn)生事件document.onmousedown=x 單擊鼠標鍵產(chǎn)生事件
document.body.scrollTop; 返回和設置當前豎向滾動條的坐標值,須與函數(shù)配合,document.body.scrollLeft; 返回和設置當前橫向滾動務的坐標值,須與函數(shù)配合,document.title document.title="message"; 當前窗口的標題欄文字document.bgcolor document.bgcolor="顏色值"; 改變窗口背景顏色document.Fgcolor document.Fgcolor="顏色值"; 改變正文顏色document.linkcolor document.linkcolor="顏色值"; 改變超聯(lián)接顏色document.alinkcolor document.alinkcolor="顏色值"; 改變正點擊聯(lián)接的顏色document.VlinkColor document.VlinkColor="顏色值"; 改變已訪問聯(lián)接的顏色document.forms.length 返回當前頁form表單數(shù)document.anchors.length 返回當前頁錨的數(shù)量document.links.length 返回當前頁聯(lián)接的數(shù)量document.onmousedown=x 單擊鼠標觸發(fā)事件document.ondblclick=x 雙擊鼠標觸發(fā)事件defaultStatus window.status=defaultStatus; 將狀態(tài)欄設置默認顯示
function function xx(){...} 定義函數(shù)isNumeric 判斷是否是數(shù)字innerHTML xx=對象.innerHTML 輸入某對象標簽中的html源代碼innerText divid.innerText=xx 將以div定位以id命名的對象值設為XX
location.reload(); 使本頁刷新,target可等于一個刷新的網(wǎng)頁
Math.random() 隨機涵數(shù),只能是0到1之間的數(shù),如果要得到其它數(shù),可以為*10,再取整Math.floor(number) 將對象number轉為整數(shù),舍取所有小數(shù)Math.min(1,2) 返回1,2哪個小Math.max(1,2) 返回1,2哪個大
navigator.appName 返回當前瀏覽器名稱navigator.appVersion 返回當前瀏覽器版本號navigator.appCodeName 返回當前瀏覽器代碼名字navigator.userAgent 返回當前瀏覽器用戶代標志
onsubmit onsubmit="return(xx())" 使用函數(shù)返回值opener opener.document.對象 控制原打開窗體對象
prompt xx=window.prompt("提示信息","預定值"); 輸入語句parent parent.框架名.對象 控制框架頁面
return return false 返回值random 隨機參數(shù)(0至1之間)reset() form.reset(); 使form表單內的數(shù)據(jù)重置
split("") string.split("") 將string對象字符以逗號隔開submit() form對象.submit() 使form對象提交數(shù)據(jù)
String對象的 charAt(x)對象 反回指定對象的第多少位的字母 lastIndexOf("string") 從右到左詢找指定字符,沒有返回-1 indexOf("string") 從左到右詢找指定字符,沒有返回-1 LowerCase() 將對象全部轉為小寫 UpperCase() 將對象全部轉為大寫substring(0,5) string.substring(x,x) 返回對象中從0到5的字符setTimeout("function",time) 設置一個超時對象setInterval("function",time) 設置一個超時對象
toLocaleString() x.toLocaleString() 從x時間對象中獲取時間,以字符串型式存在typeof(變量名) 檢查變量的類型,值有:String,Boolean,Object,Function,Underfined
window.event.button==1/2/3 鼠標鍵左鍵等于1右鍵等于2兩個鍵一起按為3window.screen.availWidth 返回當前屏幕寬度(空白空間)window.screen.availHeight 返回當前屏幕高度(空白空間)window.screen.width 返回當前屏幕寬度(分辨率值)window.screen.height 返回當前屏幕高度(分辨率值)window.document.body.offsetHeight; 返回當前網(wǎng)頁高度window.document.body.offsetWidth; 返回當前網(wǎng)頁寬度window.resizeTo(0,0) 將窗口設置寬高window.moveTo(0,0) 將窗口移到某位置window.focus() 使當前窗口獲得焦點window.scroll(x,y) 窗口滾動條坐標,y控制上下移動,須與函數(shù)配合window.open() window.open("地址","名稱","屬性") 屬性:toolbar(工具欄),location(地址欄),directions,status(狀態(tài)欄), menubar(菜單欄),scrollbar(滾動條),resizable(改變大小), width(寬),height(高),fullscreen(全 屏),scrollbars(全屏時無滾動條無參 數(shù),channelmode(寬屏),left(打開窗口x坐標),top(打開窗口y坐標) window.location = 'view-source:' + window.location.href 應用事件查看網(wǎng)頁源代碼;
a=new Date(); //創(chuàng)建a為一個新的時期對象y=a.getYear(); //y的值為從對象a中獲取年份值 兩位數(shù)年份y1=a.getFullYear(); //獲取全年份數(shù) 四位數(shù)年份m=a.getMonth(); //獲取月份值d=a.getDate(); //獲取日期值d1=a.getDay(); //獲取當前星期值h=a.getHours(); //獲取當前小時數(shù)m1=a.getMinutes(); //獲取當前分鐘數(shù)s=a.getSeconds(); //獲取當前秒鐘數(shù)
對象.style.fontSize="文字大小";單位:mm/cm/in英寸/pc帕/pt點/px象素/em文字高1in=1.25cm1pc=12pt1pt=1.2px(800*600分辯率下)
文本字體屬性: fontSize大小 family字體 color顏色 fontStyle風格,取值為normal一般,italic斜體,oblique斜體且加粗 fontWeight加粗,取值為100到900不等,900最粗,light,normal,bold letterSpacing間距,更改文字間距離,取值為,1pt,10px,1cm textDecoration:文字修飾;取值,none不修飾,underline下劃線,overline上劃線 background:文字背景顏色, backgroundImage:背景圖片,取值為圖片的插入路徑
點擊網(wǎng)頁正文函數(shù)調用觸發(fā)器:
1.onClick 當對象被點擊2.onLoad 當網(wǎng)頁打開,只能書寫在body中3.onUnload 當網(wǎng)頁關閉或離開時,只能書寫在body中4.onmouseover 當鼠標懸于其上時5.onmouseout 當鼠標離開對象時6.onmouseup 當鼠標松開7.onmousedown 當鼠標按下鍵8.onFocus 當對象獲取焦點時9.onSelect 當對象的文本被選中時10.onChange 當對象的內容被改變11.onBlur 當對象失去焦點onsubmit=return(ss())表單調用時返回的值
直線 border-bottom:1x solid black虛線 border-bottom:1x dotted black點劃線 border-bottom:2x dashed black雙線 border-bottom:5x double black槽狀 border-bottom:1x groove black脊狀 border-bottom:1x ridge black
1.邊緣高光glow(color=顏色,strength=亮光大小)
2.水平翻轉fliph() 使對象水平翻轉180度
3.垂直翻轉flipv() 使對象垂直翻轉180度
4.對象模糊blur(add=true/false direction=方向 strength=強度) add指定是否按印象畫派進行模糊direction模糊方向strength模糊強度5.對象透明alpha(opaction=0-100,finishopacity=0-100,style=0/1/2/3) opaction對象整體不透明值finishopacity當對象利用了漸透明時該項指定結束透明位置的不透明值style指定透明方式0為整體透明,1為線型透明,2為圓型透明,3為矩形透明6.去除顏色chroma(color=顏色值)使對象中顏色與指定顏色相同區(qū)域透明7.建立陰影dropshadow(color=陰影顏色,offx=水平向左偏離像素,offy=水平向下偏離像素)8.去色gray()使對象呈灰度顯示9.負片效果invert()使對象呈底片效果10.高光light()使對象呈黑色顯示11.遮蓋mask(color=顏色)使整個對象以指定顏色進行蒙板一次
opacity 表透明度水平.0~100,0表全透明,100表完全不透明finishopacity表想要設置的漸變透明效果.0~100.style 表透明區(qū)的形狀.0表統(tǒng)一形狀.1表線形.2表放射形.3表長方形.startx.starty表漸變透明效果的開始時X和Y坐標.finishx,finishy漸變透明效果結束時x,y 的坐標.add有來確定是否在模糊效果中使有原有目標.值為0,1.0表"否",1表"是".direction設置模糊的方向.0度表垂直向上,45度為一個單位.默認值是向左270度.left,right,down,up.strength 只能用整數(shù)來確定.代表有多少個像素的寬度將受到模糊影響.默認是5個.color要透明的顏色.offx,offy分別是x,y 方向陰影的偏移量.positive指投影方式.0表透明像素生成陰影.1表只給出不透明像素生成陰影..
AddAmbient:加入包圍的光源.AddCone:加入錐形光源.AddPoint加入點光源Changcolor:改變光的顏色.Changstrength:改變光源的強度.Clear:清除所有的光源.MoveLight:移動光源.
freq是波紋的頻率,在指定在對象上一區(qū)需要產(chǎn)生多少個完事的波紋.lightstrength可對于波紋增強光影的效果.顯著0~100正整數(shù),正弦波開始位置是0~360度.0表從0度開始,25表從90度開始.strength表振幅大小.
hand style="cursor:hand"crosshair style="cursor:crosshair"text style="cursor:text"wait style="cursor:wait"default style="cursor:default" help style="cursor:help"e-resize style="cursor:e-resize"ne-resize style="cursor:ne-resize"n-resize style="cursor:n-resize"nw-resize style="cursor:nw-resize"w-resize style="cursor:w-resize"s-resize style="cursor:s-resize"sw-resize style="cursor:sw-resize "se-resize style="cursor:se-resize"auto style="cursor:auto"
-->
Java NIO原理和使用 : http://www.jdon.com/concurrent/nio%D4%AD%C0%ED%D3%A6%D3%C3.htm
Merlin 給 Java 平臺帶來了非阻塞 I/O :
http://www-900.ibm.com/developerWorks/cn/java/j-javaio/index.shtml
Java NIO API詳解 : http://blog.csdn.net/daijialin/archive/2004/12/27/231384.aspx
Java New I/O的使用 : http://dev.csdn.net/develop/article/22/22063.shtm
最后推薦一本書籍: Java NIO
相信有了這些網(wǎng)絡資料,你的Java NIO的基礎一定可以得到提高!
終于整理完dbf文件讀寫的java源碼,歡迎使用
修改以下代碼
private void init(InputStream inputstream) throws JDBFException { try { stream = new DataInputStream(inputstream); int i = readHeader(); fields = new JDBField[i]; int j = 1; for(int k = 0; k < i; k++) { fields[k] = readFieldHeader(); j += fields[k].getLength(); }
if(stream.read() < 1) throw new JDBFException("Unexpected end of file reached."); nextRecord = new byte[j]; try { //stream.readFully(nextRecord); stream.read(new byte[263]); stream.readFully(nextRecord); } catch(EOFException eofexception) { nextRecord = null; stream.close(); } } catch(IOException ioexception) { throw new JDBFException(ioexception); } }
private int readHeader() throws IOException, JDBFException { byte abyte0[] = new byte[16]; try { stream.readFully(abyte0); } catch(EOFException eofexception) { throw new JDBFException("Unexpected end of file reached."); } int i = abyte0[8]; if(i < 0) i += 256; i += 256 * abyte0[9]; i -= 264; i = --i / 32; //i = --i / 32; //i--; try { stream.readFully(abyte0); } catch(EOFException eofexception1) { throw new JDBFException("Unexpected end of file reached."); } return i; }