The common method summary and working code of jquery operation string

Source: Internet
Author: User
Tags lowercase javascript array
1.javascript Array Usage
Method Description FF IE
Concat () Connects two or more arrays and returns the result. 1 4
Join () Put all the elements of an array into a string. element is delimited by the specified delimiter. 1 4
Pop () Deletes and returns the last element of the array 1 5.5
Push () Adds one or more elements to the end of the array and returns a new length. 1 5.5
Reverse () Reverses the order of elements in an array. 1 4
Shift () Deletes and returns the first element of the array 1 5.5
Slice () Returns the selected element from an existing array 1 4
Sort () To sort the elements of an array 1 4
Splice () Deletes the element and adds a new element to the array. 1 5.5
Tosource () Returns the source code for this object. 1 -
ToString () Converts the array to a string and returns the result. 1 4
toLocaleString () Converts the array to a local array and returns the result. 1 4
Unshift () Adds one or more elements to the beginning of the array and returns a new length. 1 6
ValueOf () Returns the original value of an array object 1 4
The top listed is the JavaScript array object encapsulation, through the above methods, you can easily and conveniently manipulate arrays of objects, reference URL: http://www.cnblogs.com/zyh-nhy/archive/2007/08/08/847876.html

2.checkbox
For a check box, there is generally a fixed process, many of the check boxes are due to a property, so usually use a TextBox or Label object to store the value of a family of checkboxes, only the TextBox or label properties set to hidden can be. When a page is passed or a parameter is fetched, only the TextBox or label that operates the response is required.
For example:
<div id= "Crowd" class= "CHECKBOX_BGFL" >
<input name= "Crowd" type= "hidden"/>
<p><inputtype= "checkbox" value= "137"/><span> elderly </span></p>
<p><inputtype= "checkbox" value= "138"/><span> Youth </span></p>
<p><inputtype= "checkbox" value= "139"/><span> children </span></p>
</div>
The check box family is to select the appropriate crowd, in JS to operate as follows:
Var crowd=[],//declares an array of access check box values
$ ("#crowd input:checkbox:checked"). each (function () {
Crowd.push (This.value);
})//Traverse check box to save the selected value in Crowd array
$ ("#crowdinput: Hidden"). Val (Crowd.join (","))//Remove values from the crowd array, and string them into a string, separated by commas between values.
For example, select the elderly and children, the parameter format is as follows: ...? crowd=137,139

3.select
The select operation in jquery is relatively simple, but you can add option items dynamically through the Append () function.
For example, there is a select control in the page as follows:
<select id= "Crowd" name= "crowd" >
<optionvalue= "-1" > Please select </option>
</select>
The JS code looks like this:
var crowd= "Old person 137, youth 138, children 139"; Array of option strings
Crowd=crowd.split (",");//String split
vartemp=$ ("#crowd");//Get the objects on the page
$each (Crowd,function () {//Traverse option string
var value=this.split (""); To continue separating the option string
Temp.append ($ ("<option/>"). html (value[0]). attr ("value", value[1));//Add option
});
At this point, the initialization of the Select option is complete, and because the control is in most cases a single value used, the acquisition of the form value does not need to be written again
Also, select the most important event to count onchange, simply add the onchange event declaration to the page and then process it in jquery.

4. String function
The packaging of strings is a very important application in many languages, because very practical, the use of probability is also very high, JS is no exception, the string is a series of encapsulation, the specific methods are as follows:
Method Description FF IE
Anchor () Create an HTML anchor. 1 3
Big () Displays a string in a large font. 1 3
Blink () Displays a flashing string. 1
Bold () Use bold to display the string. 1 3
CharAt () Returns the character at the specified position. 1 3
charCodeAt () Returns the Unicode encoding of the character at the specified position. 1 4
Concat () The connection string. 1 4
Fixed () Displays a string in typewriter text. 1 3
FontColor () Displays a string using the specified color. 1 3
FontSize () Displays a string using the specified dimensions. 1 3
fromCharCode () Creates a string from a character encoding. 1 4
IndexOf () Retrieves a string. 1 3
Italics () Displays a string using italic. 1 3
LastIndexOf () Searches for a string from the back forward. 1 3
Link () Displays the string as a link. 1 3
Localecompare () Compares two strings in a local-specific order. 1 4
Match () Finds one or more matches that are being expressed. 1 4
Replace () Replaces the substring that matches the regular expression. 1 4
Search () Retrieves the value that matches the regular expression. 1 4
Slice () Extracts a fragment of a string and returns the extracted part in a new string. 1 4
Small () Use the small font size to display the string. 1 3
Split () Splits the string into an array of strings. 1 4
Strike () Use strikethrough to display strings. 1 3
Sub () Displays the string as subscript. 1 3
SUBSTR () Extracts a specified number of characters from the starting index number in a string. 1 4
SUBSTRING () Extracts the characters between two specified index numbers in a string. 1 3
SUP () Displays the string as superscript. 1 3
toLocaleLowerCase () Converts the string to lowercase. - -
toLocaleUpperCase () Converts the string to uppercase. - -
toLowerCase () Converts the string to lowercase. 1 3
toUpperCase () Converts the string to uppercase. 1 3
Tosource () Represents the source code for an object. 1 -
ToString () Returns a string. - -
ValueOf () Returns the original value of a string object. 1 4
Reference URL: http://www.w3school.com.cn/js/jsref_obj_string.asp

5. As for the use of other controls, let's not dwell on them, later used in writing, the form element is added after the completion of the form is submitted, perhaps used to use HTML page common objects, such as request, such as the set parameters, or directly behind the address, no matter how to deal with, write a lot of code, After using jquery, however, this work becomes unusually simple. The reason is the use of the Serialize () method.
Examples are as follows:
HTML:
<form name= "Form1" Id= "Form1" method= "POST" >
<input type= ' text ' name= ' name ' value= ' John '/> <input type= ' text ' name= ' location ' value= ' ' Boston '/>

<button name= "BT" click= "Btclick" >

</form>

jquery code:

<script type= "text/ Javasctipt ">

function Btclick ()

{

window.location.href=url+"? "  +$ ("#form1"). Serialize ();

}

</script>

Result:
 Url?name=john&location=boston//Order Amount Information     var $orderMoneyInfo = $ (' #track ' +orderid). Children (' TD
'). EQ (3). text ();
         //Split Amount and payment method copy     var Moneyindex = $orderMoneyInfo. IndexOf (".");
         var $moneyInfo = $orderMoneyInfo. substr (0, moneyindex+3);
    var $paymentWayInfo = $orderMoneyInfo. substr (moneyindex+3, $orderMoneyInfo. length);               var $contend =          "<div Id=\ "mbz\" > "+         "     <div class=\ "m-text\" ><i class=\ "Bg-joy\" ></i> "+         "         <p class=\
"Ftx-04\" >replaceValue</p> "+         "     </div> "+                 &Nbsp;     "<div class=\" M minfo\ ">" +          "     <div class=\ "mt\" >

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.