實用js片段

2022-07-15 17:18:10 字數 2434 閱讀 3906

演算法

//加法    add(10,2)  //12

function add(a, b) catch (f)

try catch (f)

return e = math.pow(10, math.max(c, d)), (mul(a, e) + mul(b, e)) / e;

}//減法 sub(10,2) //8

function sub(a, b) catch (f)

try catch (f)

return e = math.pow(10, math.max(c, d)), (mul(a, e) - mul(b, e)) / e;

}//乘法 mul(10,2) //20

function mul(a, b) catch (f)

try catch (f)

return number(d.replace(".", "")) * number(e.replace(".", "")) / math.pow(10, c);

}//除法 div(10,2) //5

function div(a, b) catch (g)

try catch (g)

return c = number(a.tostring().replace(".", "")), d = number(b.tostring().replace(".", "")), mul(c / d, math.pow(10, f - e));

}

驗證

// 判斷是否是整數

function isint(num)

// 判斷是否是數字

function isnum(num)

// 判斷是否是手機號碼

function isphone(phone) $");

return reg.test(phone);

}//只能輸入有兩位小數的正實數,多用於**

function isfloat(num) )?$");

return reg.test(num);

}//只能輸入有1位小數的正實數,多用於打折

function isfloat1(num) )?$");

return reg.test(num);

}

獲取當前日期

//獲取當前時間年-月-日     getnowtime()   //2017-09-23

function getnowtime()

function checknum(n)

return num

}

jquery 請求

//通用get請求

function commonget(url, success, complete) else

typeof complete === "function" && complete(resp);

},error: function ()

});}//通用post請求

function commonpost(url, data, success, complete) ,500)

$(document).ajaxstart(function () )透明度的白色背景

$(".loading").show();

})$(document).ajaxsuccess(function () )

$.ajax( else

typeof complete === "function" && complete(resp);

},error: function (resp)

});}

位址引數方法

// 

// getquerystring("haha")

//獲取位址列引數

function getquerystring(name)

//changeurlarg(url, 'haha', 33); //

//修改位址列引數

function changeurlarg(url, arg, val)

//獲取字串長度

function getbytelen(val)

js,form表單資料轉化為json格式

//自定義函式處理queryparams的批量增加    jsonarr.serializejsonobject()

$.fn.serializejsonobject = function () ;

var form = this.serializearray();

$.each(form, function ()

json[this.name].push();

} else

});return json;

}

java 實用片段整理

1 反射tostring 優勢 簡潔 無須任何配置 model 屬性變化 無需修改tostring 缺陷 安全性問題 反射私有屬性值也會暴露 public static string objecttostring object condition 2 初始化list public static ar...

常用js片段

滑鼠滾輪事件 content on mousewheel dommousescroll function event else if delta 0 驗證碼倒計時 jquery版本 var times 60,timer null send on click function else 1000 常用...

原生js片段

123 4567 891011 1213 1415 1617 1819 2021 2223 2425 2627 2829 3031 3233 3435 36varcookie else 設定 set function name,value,expires 刪除 del function name d...