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