JavaScript common code Snippets in H5

Source: Internet
Author: User

/** * Bulk Replacement method, batch filter special characters, usually used in the various editors after the use of the content added on the app to edit on the application * James.wang 2016-11-11 * use: Recont (content,["<br>", " <br/> "," <p> "," </p> "]) * @param {object} strcont what to replace * @param {object} array of strings to be replaced in the array contents*/functionReediter (Strcont, array) { for(varIinchArray) {        varitem =Array[i]; //alert (item);        varReg =NewREGEXP ("\ \" + Item, "G"); Switch(item) { Case' <br> ': Strcont= Strcont.replace (Reg, "\ n"));  Break;  Case' <br/> ': Strcont= Strcont.replace (Reg, "\ n"));  Break;  Case' <p> ': Strcont= Strcont.replace (Reg, "");  Break;  Case' </p> ': Strcont= Strcont.replace (Reg, "\ n"));  Break;  Case' &nbsp; ': Strcont= Strcont.replace (Reg, "\");  Break; default: Strcont= Strcont.replace (Reg, "");  Break; }    }    returnStrcont;}
/** * Get all selected checkbox values * The return value is a comma-delimited string, such as: 2562,2568,6532,5268 if there is no option to return an empty*/functionGetcheckbox () {varChk_value = []; varStringValue = ""; $(' Input[name= ' Grade "]:checked '). each (function() {Chk_value.push ($ ( This). Val ());    }); if(Chk_value.length = = 0)        return""; Else {         for(varIinchchk_value) {StringValue+ = Chk_value[i] + ', '; }
Stringvalue=stringvalue.substring (0, stringvalue.length-1); Remove the last comma}returnStringValue;}
/* * Generate a unique  string */ function NewGuid () {    function  S4 () {        return ((1 + math.random ()) * 0x10000) | 0). ToString (+). SUBSTRING (1);    }     return (S4 () + S4 () + "-" + S4 () + "-" + S4 () + "-" + S4 () + "-" + S4 () + S4 () + S4 () );}
/** * Stitching picture attachment, add the current domain name as the full path * @param {Object} attachments comma-delimited attachment string in front of the picture path*/functionpathstring (attachments) {if(Attachments! = ' && attachments! = ' &nbsp; ' && attachments! =NULL) {        varPathstr = ' '; varAttarr = Attachments.split (', ');  for(varIinchAttarr) {Pathstr+ = host + Attarr[i] + ","; }        returnPathstr.substring (0, Pathstr.length-1); } Else {        return‘‘; }}
/** * Replace the textarea and whitespace with the corresponding HTML expression characters * @param {object} Strcont * @param {object} array*/functionRetextarea (Strcont, array) { for(varIinchArray) {        varitem =Array[i]; varReg =NewREGEXP ("\ \" + Item, "G"); Switch(item) { Case' \ r \ n ': Strcont= Strcont.replace (Reg, "<br/>");  Break;  Case‘\ ‘: Strcont= Strcont.replace (Reg, "&nbsp;");  Break; default: Strcont= Strcont.replace (Reg, "");  Break; }    }    returnStrcont;}
//An extension to date that converts date to a string of the specified format//the Month (m), Day (d), hour (h), Minute (m), second (s), quarter (q) can be used with 1-2 placeholders,//year (Y) can use 1-4 placeholders, milliseconds (S) with only 1 placeholders (1-3 digits)//Example://(New Date ()). Format ("Yyyy-mm-dd hh:mm:ss. S ") ==> 2006-07-02 08:09:04.423//(New Date ()). Format ("yyyy-m-d h:m:s.s") ==> 2006-7-2 8:9:4.18Date.prototype.Format =function(FMT) {//Author:meizz    varo = {        "m+": This. GetMonth () + 1,//Month"D+": This. GetDate (),//Day"H +": This. GetHours (),//hours"m+": This. getminutes (),//points"S+": This. getseconds (),//seconds"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. length));  for(varKincho)if(NewRegExp ("(" + K + ")"). Test (FMT)) FMT = Fmt.replace (regexp.$1, (regexp.$1.length = = 1)? (O[k]): (("XX" + o[k]). substr ("" +o[k])); returnFMT;}

JavaScript common code Snippets in H5

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.