而str.replace(/\-/g,"!")則可以全部替換掉匹配的字元(g為全域標誌)。 replace() The replace() method returns the string that results when you replace text matching its first argument (a regular expression) with the text of the second argument (a string). If the g (global)
複製代碼 代碼如下: function f1(){ var n = 999; nAdd = function(){ n += 1; } function f2(){ alert(n); } return f2; } 這裡的閉包是f1,封閉了一個變數n和一個函數f2。 我們先無視nAdd,盡量保持原貌重寫一下這個函數。 複製代碼 代碼如下: function f1(){ var n = 999; var f2 = function(){ alert(n); }; return f2; }
首先,要實現產生n以內不重複的隨機數,並將產生的隨機數放入另一個Array中,用以下方法來完成: 複製代碼 代碼如下: function getRandomNumbers(count) { var numbers = new Array(); var original = new Array(); for (var i=0;i<count;i++) { original[i] = i+1; } original.sort(function(){ return 0.5 -
複製代碼 代碼如下:/** * 折半尋找字元在數組中的位置(有序列表) * @param array 被檢索的數組 * @param x 要尋找的字元 * @type int * @returns 字元在數組中的位置,沒找到返回-1 */ function binarySearch(array,x){ var lowPoint=1; var higPoint=array.length; var returnValue=-1; var midPoint; var found=false;
複製代碼 代碼如下: var picarry = {}; var lnkarry = {}; var ttlarry = {}; function FixCode(str){ return str.replace("'","="); } var t=document.getElementById("pictable"); var rl=t.rows.length; var baseu= document.URL.replace(/(http.*\/)(.*)/, "$1"); if(baseu.
appendChild定義 appendChild(newChild: Node) : Node Appends a node to the childNodes array for the node. Supported: IE 5.0+, Mozilla 1.0+, Netscape 6.0+, Safari 1.0+, Opera 7.0+ 添加一個節點到指定的節點的子節點數組中,讀起來好象有點拗口,簡單地說就是將元素添加到指定的節點中 appendChild用法