jquery Basics 1

Source: Internet
Author: User

Three basic methods of $.each,$.trim,$.map of jquery

1.$.each ()

Function: Equivalent to a for array element traversal can also be done on the JSON object, the key value pair object traversal through the callback function

var arrint=[1,2,3,4,5];
$.each (Arrint,function (key,value) {
if (key==2)
Return false;//equivalent to break;

Alert (key+ "" +value);
});
var p={' name ': ' Zhangsan ', ' sex ': ' Male ', ' email ': ' [email protected] '};
$.each (P,function (key,value) {
Alert (key+ "" +value);
// });

2.$.trim ()

Function: Remove the string from the end of the white space character

var str= "Qwe"
Alert ($.trim (str));

3.$.map ()

Function: Operate on an array

var arrint=[10,33,44,55,66];
Arrint=$.map (Arrint,function (element,index) {
return element*2;
// });
alert (arrint);
Arrint=$.map (Arrint,function (element,index) {
if (index>3)
return element*2;
else return element;
// });
alert (arrint);

4.dom Objects and jquery objects

Dom-->jquery $ (DOM)
Jquery-->dom jqueryobject.get (0) or jqueryobject[0]
Question: Why convert DOM objects to jquery objects
Troubleshoot compatibility issues with some browsers

var Divobj=document.getelementbyid (' Div1 ');
Divobj.innerhtml= "Hello World";
Dom-->jquery
$DVOBJ =$ (divobj);
$DVOBJ. html ("Hello World");

Jquery-->dom
var domdiv= $dvObj [0];
Domdiv.innerhtml= "1232456QWEQWRQWR";

document.getElementById (' btn '). Onclick=function () {
var $txt =$ (document.getElementById (' txt '));
Alert ($txt. Val ());
CSS style set by jquery CSS method
$txt. CSS (' border ', ' 1px solid blue ');
$txt. css (' float ', ' right ');

$txt. CSS ({
border: ' 2px solid black ',
' Color ': ' Red ',
float: ' Right ',
FontSize: ' 20px ',
BackgroundColor: ' Pink ',
Distinguishing between keywords and strings
});
$link =$ (document.getElementById (' link '));
$link. html (' Wowowowoow ');
$link. html (' ');

jquery Part method

1.css ()

2.

Val ()----value (); Form element content
HTML ()----innerHTMl ();//text plus element
Text ()----innerText ();//Plain text

jquery Basics 1

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.