A variety of common JS function finishing

Source: Internet
Author: User
Tags getdate

JS Get page address parameters

The code is as follows:

function Geturlpara (paraname)

{

var surl = location.href;

var sreg = "(?:/ /?| & {1} "+ Paraname +" = ([^&]*)

var re = new RegExp (Sreg, "GI");

Re.exec (sURL);

return regexp.$1;

}

Address jump

The code is as follows:

var pn = $ ("#gotopagenum"). Val ();//#gotopagenum是文本框的id属性

Location.href = "newlist.aspx?pagenum=" +pn;//location.href implement client page jump

thousand-bit

The code is as follows:

function Convert (Money)

{

var s = money; Get Decimal data

s + + "";

if (S.indexof (".") = = 1) s + = ". 00"; If there is no decimal point, make a decimal point and 00 in the back

if (/.d$/.test (s)) s + = "0"; Regular judgment

while (/d{4} (. |,)/.test (s))//Meet the criteria to replace

s = S.replace (/(d) (D{3} (. |,))/, "$1,$2"); Add one at every 3-bit

return s;

}

Judge whether the number

The code is as follows:

function IsNumeric (TXT) {

if (txt = = "") {

return false;

}

if (Txt.indexof (",") > 0) {

txt = txt.replace (",", "");

}

if (isNaN (TXT)) {

return false;

}

else {

return true;

}

}

Format a number as a two-digit decimal

The code is as follows:

function Changetwodecimal_f (x) {

var f_x = parsefloat (x);

if (isNaN (f_x)) {

Alert (' Function:changetwodecimal->parameter error ');

return false;

}

f_x = Math.Round (f_x * 100)/100;

var s_x = f_x.tostring ();

var pos_decimal = S_x.indexof ('. ');

if (Pos_decimal < 0) {

Pos_decimal = S_x.length;

S_x + = '. ';

}

while (s_x.length <= Pos_decimal + 2) {

s_x + = ' 0 ';

}

return s_x;

}

The function parsefloat parseint for the digital operation of Js

JS Current date YYYY-MM-DD the preset query condition

The code is as follows:

var now = new Date ();

var year = Now.getyear ();

if (Now.getyear () < 1900) {

Year = Now.getyear () + 1900;

}

var month = Now.getmonth () + 1;

var day = Now.getdate ();

if (Month <) month = "0" + month;

if (Day < ten) Day = "0" + day;

$ ("#txtDate1"). Val (year.tostring () + "-" + month.tostring () + "-01");

$ ("#txtDate2"). Val (year.tostring () + "-" + month.tostring () + "-" + day.tostring ());

Js gets the timestamp and replaces the GUID in some scenarios

The code is as follows:

function Nowtimecode ()

{

var result= "";

var now = new Date ();

var year = Now.getyear ();

if (Now.getyear () < 1900) {

Year = Now.getyear () + 1900;

}

var month = Now.getmonth () + 1;

var day = Now.getdate ();

var hour = now.gethours ();

var minutes = now.getminutes ();

var second = Now.getseconds ();

var millisecond = Now.getmilliseconds ();

if (Month <) month = "0" + month;

if (Day < ten) Day = "0" + day;

if (hour <) hour = "0" + hour;

if (minutes <) minutes = "0" + minutes;

if (second <) Second = "0" + second;

if (Millisecond < 10)

Millisecond = "+" + millisecond;

Else

{

if (Millisecond < 100)

{

Millisecond = "0" + millisecond;

}

}

result = year.tostring () + month.tostring () + day.tostring () + hour.tostring () + minutes.tostring () + second.tostring () + Millisecond.tostring ();

return result;

}

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.