jquery Common operations @ Test sharing

Source: Internet
Author: User

Formatted date time is 2017-07-09

functionformatdate (dates) {varmydate=NewDate (dates); Varmon=mydate.getmonth () +1; Mon= Mon.tostring (). Length <=1?"0"+Mon:mon; Vard=mydate.getdate (); D= D.tostring (). Length <=1?"0"+d:d; Varh=mydate.gethours (); H= H.tostring (). Length <=1?"0"+h:h; Varm=mydate.getminutes (); M= M.tostring (). length = =1?"0"+m:m; VARs=mydate.getseconds (); S= S.tostring (). length = =1?"0"+s:s; Returnmydate.getfullyear ()+"-"+mon+"-"+d+" "+h+":"+m+":"+s;}

Convert string to date format

New Date ("7","Up", 0,0,0); Console.log (mydate); // the new date () converts the number to the date type. However, the format "2017-07-18" cannot be converted to a date format. 

Boostrap: Adding a Month view control

varC="Form-control input-smdatepicker-input";$("input[name = ' _lis_field3 ']"). attr ("class", c); $ (". Datepicker-input"). DateTimePicker ({language:"ZH-CN", Format:"yyyy-mm",//Select the format to fill in the monthAutoClose:true, Minview:" Year", Startview:' Year',//set to Year Month viewtodaybtn:true, Pickerposition:"Bottom-left"        });

Scope

Re-declaring variables inside a method can cause variable elevation

var ' Test ' ;  (function () {      //  undefined      var'test1' ;  

Jquery Digital Operations

Avoid IE8 number anomalies with Parserint (str, in-process)

Under IE8, parseint (' 09 ') Calculates 0,parseint (' 010 ') as 8 instead of 8, 10, which we want. With parseint (' 08 ', 10) that can be converted to normal;

Determine if non-string

if (IsNaN (number (scoreval))) {}

Save 2 digits after the decimal point

B.tofixed (2);

ULR operation

Automatically refreshes the current URL

Window.location.reload ();

URL Jump:

location.href=src+ "? num=" +data+ "&device=" +device1+ "&situation=" +situation1+ "&checkSituation=" + checksituation1;//jump to another page,//can pass other parameters to another page

This window opens another page

window.open (Son_url, "_self");

Get the parameters in the URL

Console.log (WINDOW.LOCATION.SEARCH.SUBSTR (1));//Get the string after the URL?

Get the parameters in the URL by using a regular

VarName =function (name) {varReg =NewREGEXP ("(^|&)"+name +"= ([^&]*) (&|$)"); varR =window.location.search.substr (1). Match (REG); if(r!=NULL)returndecodeURI (r[2]); Returnnull;} Console.log (Name ("Dwname"));

jquery Common operations @ Test sharing

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.