JS Common tool functions (continuous recording)

Source: Internet
Author: User
Tags ticket

Mode 1//set Cookiefunction setcookie (name, value)//two parameters, one is the name of the cookie, one is the value {    var days = 30;//This cookie will be saved for 30 day    var E XP = new Date ();    New Date ("December, 9998");    Exp.settime (Exp.gettime () + days * * * * +);    Document.cookie = name + "=" + Escape (value) + "; expires=" + exp.togmtstring ();} Read the cookie function GetCookie (name)      {    var arr = document.cookie.match (new RegExp (^|) + name + "= ([^;] *)(;|$)"));    if (arr! = null) return unescape (arr[2]); return null;} Delete the cookie function Delcookie (name) {     var exp = new Date ();     Exp.settime (Exp.gettime ()-1);     var cval=getcookie (name);     if (cval!=null)         document.cookie= name + "=" +cval+ "; expires=" +exp.togmtstring ();}
2. Time type, string mutual transfer
JS time-to-string Date.prototype.Format = function (FMT) {//author:meizz var o = {"m+": This.getmonth () + 1,//month  "D+": this.getdate (),//day "H +": this.gethours (),//Hour "m+": this.getminutes (),//Sub "s+"    : This.getseconds (),//sec "q+": Math.floor ((This.getmonth () + 3)/3),//Quarterly "S": This.getmilliseconds ()    milliseconds}; if (/(y+)/.test (FMT)) FMT = Fmt.replace (regexp.$1, (this.getfullyear () + ""). substr (4-REGEXP.$1.L    Ength)); For (var k in O) if (New RegExp ("(" + K + ")"). Test (FMT)) FMT = Fmt.replace (regexp.$1, (regexp.$1.lengt h = = 1)?    (O[k]): (("XX" + o[k]). substr (("" + O[k]).)); return FMT;};    JS string to Time/* * string and date conversion */str2date = function (c_date) {if (!c_date) return "";    var temparray = C_date.split ("-");        if (temparray.length! = 3) {alert ("you entered the date format incorrectly, the correct format: YYYY-MM-DD hh:mm:ss");    return 0; } var Datearr = C_date.split ("");    var date = null;         if (datearr.length = = 2) {var yymmdd = Datearr[0].split ("-");        var HHMMSS = Datearr[1].split (":");    Date = new Date (yymmdd[0], yymmdd[1]-1, yymmdd[2], hhmmss[0], hhmmss[1], hhmmss[2]);    } else {date = new date (temparray[0], temparray[1]-1, temparray[2], 00, 00, 01); } return date;};
3, bank card number four-bit fill space
The bank card number is displayed in 4-bit spaces (     using onkeyup (Setbanknostyle (this.value))   ) function Setbanknostyle (bankno) {    var lkeycode = (Navigator.appname = = "Netscape")? Event.which:event.keyCode;    if (lkeycode! = 8) {        if (Bankno.value = = "") return;        var account = new String (bankno.value). Replace (/\s/g, ");        var strtemp = "";        for (var i = 0; i < account.length; i++) {            if (!isnan (Account[i])) {                strtemp = strtemp + account[i];            }        }        var strvalue = strtemp.substr (0, +);        strtemp = "";        for (var j = 0; J < Strvalue.length; J + +) {            if ((j + 1)% 4 = = 0) {                strtemp = strtemp + strvalue[j] + ""; 
   } else {                strtemp = strtemp + strvalue[j];            }        }        $ (Bankno). Val (strtemp);    }}
4, the text content part selected
O is the current object, such as the Text Field object//b is the starting position (begin), and E is the end position (end) function Textselect (o, B, e) {var b = parseint (b, 10),        E = parseint (e, 10);        var L = o.value.length;            if (l) {//If non-numeric, indicates the selection from the starting position to the end position if (!b) {b = 0;            } if (!e) {e = l;            }//If the value exceeds the length, it is the length of the current object value if (B > L) {b = l;            } if (E > L) {e = l;            }//If negative, add the length value if (b < 0) {b = l + b;            } if (E < 0) {e = L + E;                } if (o.createtextrange) {//ie browser var range = O.createtextrange ();                Range.movestart ("character",-l);                Range.moveend ("character",-l);                Range.movestart ("character", b);                Range.moveend ("character", e);            Range.Select ();            } else {    O.setselectionrange (b, E);            O.focus ();    }        }    };    var txt = document.getElementById (' txt '); Textselect (TXT, ' a ', 11);
5, RMB to capitalize the number
/* "The basic rules for the correct filling of notes and settlement vouchers" the various bills and settlement vouchers filled by banks, units and individuals are the important basis for payment settlement and cash receipt and payment, which is directly related to the accurate, timely and safe settlement. Bills and settlement vouchers are banks, units and individuals to record accounts of accounting documents, is a record of economic business and clear economic responsibility of a written proof. Therefore, the completion of bills and settlement vouchers, must be standardized, standardized, to complete the elements, the correct numbers, clear handwriting, good leakage, not scrawled, to prevent alteration. Chinese capital Amount number Application Block letters or running script fill in, such as one (one), II (ii), three, the restaurant (the restaurant), Wu (WU), Lu (LU), qi, BA, JIU, pick, Bai, Qian, million (million), billion, yuan, angle, minute, 0, the whole (positive) and so on. Do not use one or two (two), three or four, five or six, seven or eight, nine or 10, read, Mao, another (or 0), and shall not be self-made simplified characters. If the amount of digital writing in the use of traditional Chinese characters, such as II, Lu, million, million, round, should also be entertained. First, the Chinese capital amount to "Yuan", after the "Yuan", should be written "whole" (or "positive") word, after "angle", you can not write "whole" (or "positive") word. The uppercase amount number is "divided" and the word "whole" (or "positive") is not written after "Min". Second, the Chinese capital amount should be marked "RMB" before the words, capital amount number has "cent", "points" after not write "whole" (or "positive") word. Third, the Chinese capital amount should be marked "renminbi" before the words, capital amount should be immediately after the words "RMB" to fill in, not leave blank. If the words "RMB" are not printed before the capital amount number, the words "RMB" shall be added. In the capital amount of bills and settlement vouchers may not be pre-printed fixed "thousand, Bai, pick, million, Qian, Bai, pick, Yuan, angle, points," the words. When there is "0" in the numeral of the Arabic numerals, the Chinese capital should be written according to the rules of Chinese language, the amount of figures and the requirement of preventing alteration. Examples are as follows: 1 • Arabic numerals in the middle of the "0", the Chinese capital to write "0" word, such as ¥1409.50, should be written in the Yuan Yi Qian bai Shangyuan Wu Kok. 2 • There are several "0" in the middle of the Arabic numerals, the Chinese capital amount can only write a "0" word, such as ¥6007.14, should be written in RMB thousand 0 qi yuan cents. 3 · Arab amount number Wanwi yuan is "0", or the middle of the number of consecutive "0", the million-bit, the yuan is also "0", but the thousand, the corner is not "0", the Chinese capital amount can be written only a 0 words, you can also do not write "0" word. such as ¥1680.32, should be written as RMB Ba 0 three cents, or write the Yuan hundred Yuan Bai Ba three points, and such as ¥107000.53, should be written in renminbi a million qi thousand yuan 0 Wu angle three points, or write a yuan to pick up million zero qi thousand yuan Wooker points. 4 • Arabic amount The angular position is "0", while the sub-position is not "0", the Chinese capitalAfter the amount "Yuan" should be written "0" word. such as ¥16409.02, should be written as RMB Wan Shangyuan 0 cents, and as ¥325.04, should be written in the Yuan San Bai dollar 0 points. In front of the Arabic small amount figures, the renminbi symbol "¥" should be filled in. Arabic small amount of numbers to be carefully filled out, not ligatures distinguish unclear. The ticket's ticketing date must be capitalized in Chinese. In order to prevent the date of ticket issuance, when filling the month, day, month for one, II and one pick up, the day for one to Shong, II pick up and pick up, should be in its former plus "0", the day to pick up the nine, should be in its front plus "one". such as January 15, should be written 0 one month to pick up Wooge. Again, as of October 20, should be written 0 a month 0 to pick up the day. Seven, the ticket issued by the date of the use of lowercase, the bank is inadmissible. If the capital date is not completed according to the requirement specification, the bank may accept it, but the ticket holder shall bear the loss. *///Digital to RMB capital function Convertchinesemoney (money) {var cnnums = new Array ("0", "one", "II", "three", "Restaurant", "WU", "Lu", "Qi", "ba", " Nine "); The number of Chinese characters var cnintradice = new Array ("", "Pick", "Bai", "thousand"); Base unit var cnintunits = new Array ("", "Million", "billion", "Mega"); The corresponding integer part extends the unit var cndecunits = new Array ("angle", "minute", "MM", "CL"); Corresponds to fractional part unit var Cninteger = "whole"; The integer amount is followed by the character var cnintlast = "Meta"; The unit var maxnum = 999999999999999.9999 After the completion of the integer type; Maximum processing of the digital Var Integernum; Amount of Integer part var decimalnum; The amount of the decimal part var chinesestr = ""; Output the Chinese amount string var parts;    The array to use after separating the amount, the predefined if (Money = = "") {return "";    } Money = parsefloat (money); if (Money >= maxnum) {$.alert (' superThe maximum processing number ');    Return "";        } if (money = = 0) {chinesestr = Cnnums[0] + cnintlast + cninteger;    return chinesestr; } money = Money.tostring ();        Convert to String if (Money.indexof (".") = =-1) {integernum = money;    Decimalnum = ";        } else {parts = Money.split (".");        Integernum = Parts[0];    Decimalnum = Parts[1].substr (0, 4);        } if (parseint (Integernum) > 0) {//Get integral part conversion Zerocount = 0;        Intlen = Integernum.length;            for (i = 0; i < Intlen; i++) {n = integernum.substr (i, 1);            p = intlen-i-1;            Q = P/4;            m = p% 4;            if (n = = "0") {zerocount++;                } else {if (Zerocount > 0) {chinesestr + = cnnums[0]; } zerocount = 0;            Zeroing Chinesestr + = Cnnums[parseint (n)] + cnintradice[m];     } if (M = = 0 && Zerocount < 4) {           Chinesestr + = Cnintunits[q];        }} chinesestr + = Cnintlast;        The integer section is finished processing} if (decimalnum! = ") {//fractional Declen = Decimalnum.length;            for (i = 0; i < Declen; i++) {n = decimalnum.substr (i, 1);            if (n! = ' 0 ') {chinesestr + = Cnnums[number (n)] + cndecunits[i];    }}} if (chinesestr = = ") {chinesestr + = Cnnums[0] + cnintlast + cninteger;    } else if (Decimalnum = = ") {chinesestr + = Cninteger; }//If the meta bit is exactly zero, you need to fill 0//if (chinesestr.indexof (' pickup ') >= 0) {//if (Chinesestr.indexof (' min ') >= 0 | | Chinesestr.indexof (' angle ') >= 0) {//processing only to 10 yuan, and just the case of horns or points//chinesestr = CHINESESTR.SUBSTR (0, Chinesestr.indexof (    ' Yuan ') + 1) + ' 0 ' + chinesestr.substr (chinesestr.indexof (' Yuan ') + 1);        }//} else if (Chinesestr.indexof (' min ') >= 0 && chinesestr.indexof (' angle ') < 0) {//handling no corner points if (Chinesestr.indexof (' Yuan '); 0) {chinesestr = chinesestr.substr (0, Chinesestr.indexof (' Yuan ') +1) + ' 0 ' + chinesestr.substr (Chinesestr.indexof (        ' Yuan ') + 1); }} return chinesestr;}

JS Common tool functions (continuous recording)

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.