Summary of common methods of jquery operation string and working code

Source: Internet
Author: User
Tags javascript array

1.javascript Array Usage

Method Description FF IE
Concat () Joins two or more arrays and returns the result. 1 4
Join () Put all the elements of the array into a string. element is delimited by the specified delimiter. 1 4
Pop () Delete and return the last element of the array 1 5.5
Push () Adds one or more elements to the end of the array and returns the new length. 1 5.5
Reverse () Reverses the order of the elements in the array. 1 4
Shift () Delete and return the first element of the array 1 5.5
Slice () Returns the selected element from an existing array 1 4
Sort () Sorting 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 the 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 the new length. 1 6
ValueOf () Returns the original value of an array object 1 4

The above list is the JavaScript array object encapsulation, through the above method, you can easily and conveniently manipulate the object, 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 check boxes are due to a property, so usually use a TextBox or a Label object to store the value of a family check box, just need to set the TextBox or Label property to hidden. When a page is passed or gets a parameter, 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> old man </ span></p> <p><inputtype= "checkbox" value= "138"/><span> Youth </span></p> <p ><inputtype= "checkbox" value= "139"/><span> children </span></p> </div> The checkbox family is to select the appropriate population,  In JS, the operation is 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 the crowd array$ ("#crowdinput: Hidden"). Val (Crowd.join (","));//Extract the value from the crowd array, and string the values into a string, separating the values from the values with commas. For example, if the old and children are selected, the parameter format is as follows: ...? crowd=137,139
The operation of select in 3.select jquery is relatively straightforward, but you can add option items dynamically through the Append () function. For example, there is a select control on the page as follows: <select id= "Crowd" name= "crowd" ><optionvalue= "1" > Please select </option> </select> JS code as follows: Var crowd= "old man 137, youth 138, child 139";      ///Option string array crowd=crowd.split (",");//String split vartemp=$ ("#crowd");//Gets the object $each in the page (Crowd,function () {//Traversal option string var value=this.split (""); The option string continues to be delimited by Temp.append ($ ("<option/>"). html (value[0]). attr ("value", value[1]);//Add option}); At this point, the initialization of the Select option has been completed, because the control is used for most of the single value, so the acquisition of the form value does not need to be re-written in addition to select the most important event is the number of onchange, only need to add onchange event declaration on the page, And then work on jquery.
4. String function string Wrapper is a very important application in many languages, because it is very practical, the use of probability is very high, JS is no exception, the string is a series of encapsulation, the specific method is as follows:
Method Description FF IE
Anchor () Creates an HTML anchor. 1 3
Big () Displays the string in a large font. 1 3
Blink () Displays the 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 the string as a typewriter text. 1 3
FontColor () Displays the string using the specified color. 1 3
FontSize () Displays the string using the specified dimensions. 1 3
fromCharCode () Creates a string from character encoding. 1 4
IndexOf () Retrieves a string. 1 3
Italics () Use italic to display strings. 1 3
LastIndexOf () The string is searched forward from the back. 1 3
Link () Displays the string as a link. 1 3
Localecompare () Compares two strings in a local-specific order. 1 4
Match () Found one or more matches that are being expressed. 1 4
Replace () Replace the substring that matches the regular expression. 1 4
Search () Retrieves a value that matches a regular expression. 1 4
Slice () Extracts a fragment of a string and returns the extracted part in a new string. 1 4
Small () Use a small font size to display the string. 1 3
Split () Splits a 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 the object. 1 -
ToString () Returns a string. - -
ValueOf () Returns the original value of a string object. 1 4
citation URL: http://www.w3school.com.cn/js/jsref_obj_string.asp
5. As for the use of other controls in this first not to repeat, behind the use of writing, form elements after the completion of the form is submitted, before perhaps the use of HTML page common objects, such as request settings parameters, or directly following the address, regardless of how to deal with, have to write a lot of code, However, after using jquery, the work becomes unusually simple. The reason is the use of the Serialize () method. Examples are: 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\ ">" +   & nbsp;     "    <div class=\" m-text\ "><i class=\" bg-joy\ "></i>" +          "        <p class=\" ftx-04\ ">replacevalue </p> "+        "     </div> "+                    &NBSP; " <div class=\ "M minfo\" > "+        "     <div class=\ "mt\" > 

JQuery Action String Common methods Summary and work code

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.