Jquery has long been widely used. This article lists some common functional snippets in practical applications. If you are interested, you can learn more. I hope you will not hesitate to give me any suggestions for improvement. specifies that the content of a subpage is displayed in a p on the home page. The renderiner iner can be the id or name of p on the home page.
The Code is as follows:
$. Ajax ({
Url: url,
Data: parameters,
Type: "GET ",
DataType: "html ",
Success: function (html ){
$ (RenderContainer). attr ("title", title );
((Rendercontainer).html (html );
$ (RenderContainer). dialog ({
AutoOpen: true,
Width: 590,
Height: 720,
Modal: true,
Resizable: false,
Draggable: true
});
}
});
2. Select the specified ID of the specified attribute of the specified table for an action.
The Code is as follows:
$ (". Tbl_checked tr [userid = '" + idArray [I] + "']"). remove ();
3. Delayed loading trigger event. Select the checkbox whose id contains the "userid" field and is checked, and put their IDs in the idArray.
The Code is as follows:
$ ("# Authorize_reset"). live ('click', function (){
Var idArray = [];
$ (": Checkbox [id ^ = 'userid']"). each (function (){
If ($ (this). attr ("checked") = "checked "){
IdArray. push (parseInt ($ (this). val ()));
}
});
});
});
3. select another method for selecting the checkbox whose id contains the "userid" field and is checked
The Code is as follows:
$ (": Checkbox [id ^ = 'userid'] [checked]"). each (function (){
SelectedRoleIdArray. push (parseInt ($ (this). val ()));
});
4. simple and practical click to change the style
The Code is as follows:
$ (Function (){
$ (". Tbl_checked tr"). live ('click', function (){
Var target = $ (this );
If (target. attr ("class") = "tr_checked "){
Target. removeClass ("tr_checked ");
} Else {
Target. addClass ("tr_checked ");
}
})
5. The time in the "2012-12-21" format is relatively large and needs to be converted first.
The Code is as follows:
Var compareTime = Date. parse (setTime. replace (/-/g ,"/"));
6. Obtain the current time in the format of "2012-12-21"
The Code is as follows:
(Function ($ ){
Var FormatDateTime = function FormatDateTime (){};
$. FormatDateTime = function (days ){
// Var correcttime1 = eval ('(new' + obj. replace (new RegExp ("\/", "gm"), "") + ')');
Var myDate = new Date ();
MyDate. setDate (myDate. getDate () + days );
Var year = myDate. getFullYear ();
Var month = ("0" + (myDate. getMonth () + 1). slice (-2 );
Var day = ("0" + myDate. getDate (). slice (-2 );
Var s = year + "-" + month + "-" + day;
Return s;
}
}) (JQuery );
Finally, a list similar to two-way list with jquery can be exchanged between the left and right sides.
The Code is as follows:
$ (Function (){
// Click to load the user list and Role user list
$ (". Add_remove_user"). live ('click', function (){
Var rid = $ (". current"). attr ("id"). substring ("ut _". length );
ChangeroleDialog (changeroleRoute. url (), {id: rid}, ". set_user_list ");
});
$ (". Tbl_checked tr"). live ('click', function (){
Var target = $ (this );
If (target. attr ("class") = "tr_checked "){
Target. removeClass ("tr_checked ");
} Else {
Target. addClass ("tr_checked ");
}
});
$ (". Tbrule role_checked tr"). live ('click', function (){
Var target = $ (this );
If (target. attr ("class") = "tr_checked_1 "){
Target. removeClass ("tr_checked_1 ");
} Else {
Target. addClass ("tr_checked_1 ");
}
});
$ ("# AddThisRole"). live ('click', function (){
If ($ (". tbrule role_checked tr"). first (). attr ("default_value") = 'noresresult '){
Var table = $ (". tbrule role_checked ");
$ (". Tbrule role_checked tr"). remove ();
Var tr = $ ("")
. Append ($ (""Developer.html ('name '))
. Append ($ (""Login .html ('account '))
Table. append (tr );
}
$ (". Tr_checked"). each (function (){
$ (This). remove ();
Var element = $ (this );
Var id = element. attr ("param_id ")
Var name = element. attr ("param_name ")
Var account = element. attr ("param_account ")
Var table = $ (". tbrule role_checked ");
Var tr = $ ("")
. Append ($ (""Pai.html (element. attr (" param_name ")))
. Append ($ (""Pai.html (element. attr (" param_account ")))
// Table. append (tr );
Tr. insertAfter ($ (". tb1_role_checked tr"). first ());
});
});
$ ("# DeleteThisRole"). live ('click', function (){
If ($ (". tbl_checked tr"). first (). attr ("default_value") = 'noresresult '){
Var table = $ (". tbl_checked ");
$ (". Tbl_checked tr"). remove ();
Var tr = $ ("")
. Append ($ (""Developer.html ('name '))
. Append ($ (""Login .html ('account '))
Table. append (tr );
}
$ (". Tr_checked_1"). each (function (){
$ (This). remove ();
Var element = $ (this );
Var id = element. attr ("param_roleid ");
Var name = element. attr ("param_rolename ");
Var account = element. attr ("param_roleaccount ");
Var table = $ (". tbl_checked ");
Var tr = $ ("")
. Append ($ (""Pai.html (element. attr (" param_rolename ")))
. Append ($ (""Pai.html (element. attr (" param_roleaccount ")))
// Table. insertBefore (tr, $ (". tbl_checked tr"). first ());
Tr. insertAfter ($ (". tbl_checked tr"). first ());
});
});
});
So much, the above Code is not perfect, and we hope you will not hesitate to give suggestions for improvement.