var myDate = new Date();
myDate.getYear(); //獲取當前年份(2位)
myDate.getFullYear(); //獲取完整的年份(4位,1970-????)
myDate.getMonth(); //獲取當前月份(0-11,0表明1月)
myDate.getDate(); //獲取當前日(1-31)
myDate.getDay(); //獲取當前星期X(0-6,0表明星期天)
myDate.getTime(); //獲取當前時間(從1970.1.1開始的毫秒數)
myDate.getHours(); //獲取當前小時數(0-23)
myDate.getMinutes(); //獲取當前分鐘數(0-59)
myDate.getSeconds(); //獲取當前秒數(0-59)
myDate.getMilliseconds(); //獲取當前毫秒數(0-999)
myDate.toLocaleDateString(); //獲取當前日期
myDate.toLocaleTimeString(); //獲取當前時間
myDate.toLocaleString(); //獲取日期與時間//取月份的天數function(year, month) {
var days = 32 - new Date(year, month - 1, 32).getDate();
}
JS 數值計算
var d = a * 1 + b * 1 + c * 1;
方法定義
/*
var func=function 和 function func()在乎義上沒有任何不一樣,但其解釋優先級不一樣:
後者會先於同一語句級的其餘語句。
即:
*/
{
var k = xx();
function xx(){return 5;}
}
/*
不會出錯,
而
*/
{
var k = xx();
var xx = function(){return 5;}
}
/*則會出錯。*/
JS 捕捉瀏覽器關閉/刷新 當前頁面api
var notleave = true;
window.onbeforeunload = function () {
if (notleave) {
do();
return ('確認離開當前頁面嗎?未保存的數據將會丟失!');
}
};
staticvoid Main(string[] args)
{
List<List<string>> val = new List<List<string>> {
new List<string>(newstring[] { "T" }),
new List<string>(newstring[] { "C","G" }),
new List<string>(newstring[] { "A","H","K" }),
new List<string>(newstring[] { "0","1","2","3","4","5"}),
new List<string>(newstring[] { "0","1","2","3","4","5","6","7","8","9"})
};
List<List<string>> data = composeData(val);
foreach (List<string> one in data)
{
for (int i = 0; i < one.Count; i++)
{
Console.Write(one[i]);
if (i != one.Count - 1)
{
Console.Write("_");
}
}
Console.WriteLine();
}
Console.WriteLine(data.Count);
Console.ReadKey();
}
//組合排列static List<List<string>> composeData(List<List<string>> val)
{
List<List<string>> array = val;
List<List<string>> sarr = new List<List<string>>();
sarr.Add(new List<string>());//新加空組 for (int i = 0; i < array.Count; i++)
{
List<List<string>> tarr = new List<List<string>>();//接收本輪全部組合 for (int j = 0; j < sarr.Count; j++)
{
for (var k = 0; k < array[i].Count; k++)
{
List<string> slist = new List<string>();//接收2維數組值 foreach (string str in sarr[j])
{
slist.Add(str);
}
slist.Add(array[i][k]);//追加值
tarr.Add(slist);
}
}
sarr = new List<List<string>>();
foreach (List<string> str in tarr)
{
sarr.Add(str);
}
}
return sarr;
}
vs2015啓動網站調試提示 HTTP 錯誤 403.14 - Forbidden Web 服務器被配置爲不列出此目錄的內容。
//是否被包含,是返回true,不是返回falsefunction isContained(a, b){
if(!(a instanceof Array) || !(b instanceof Array)) returnfalse;
if(a.length < b.length) returnfalse;
var aStr = a.toString();
console.info(aStr);
for(var i = 0, len = b.length; i < len; i++){
console.info(aStr.indexOf(b[i]));
if(aStr.indexOf(b[i]) == -1) returnfalse;
}
returntrue;
}
function test(){
var a = [1,2,3,4,5];
var b = [1,4,3,2];
var c = [1,6];
alert(isContained(a,b));//true
alert(isContained(a,c));//false}
網站中頁面跳轉傳參
<!-----------a.html ---------> function jump(id)
{
var url = "b.htm?id=" + id + "&v=" + Math.random();
window.open(url, '_self');
}
//公共JS中 var para = { ... }
var getUrlParams = function() {
if (para.args) {
return para.args;
} else {
var args = [];
var query = location.search.substring(1); //獲取查詢串 var pairs = query.split("&"); //在逗號處斷開for (var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexOf('='); //查找name=value if (pos == -1)
continue; //若是沒有找到就跳過 var argname = pairs[i].substring(0, pos); //提取name var value = pairs[i].substring(pos + 1); //提取value
args[argname] = unescape(value); //存爲屬性 }
return (para.args = args);
}
};
<!--------b.html:---------> var args = getUrlParams();
var step = args["id"];