Jquery-Question Answering: jquery and conflict

Source: Internet
Author: User

Jquery-Question Answering: jquery and conflict
1. var v = $ ('. summer-input: input'). val (); // obtain the input according to the class

2. var v = $ ('input [name = user \. name] '). val (); // escape name escape \\

3. var v = $ ('input: eq (-2) '). val (); // obtain the penultimate input element in the div and write a negative number.

4. The object [] $ ('div> span'hangzhou.html () is one // div> span, which is the child element of the div. The div span is all

5. if ($ ('# content '). length> 0) {$ ('# content '). remove ();} // determines whether an element exists. $ (). length> 0

6.1,
Function selectCheckbox (){
$ ('# Table thead input [type = checkbox]'). click (function () {// checkbox click Event
If ($ (this). is (": checked ")){
$ ('# Table tbody input [type = checkbox]'). prop ('checked', true); // checkbox determines whether to select, $ (). prop ('checked') = true? False/$ (). is (': checked')/$ (': checked'). length
$ ('# Table tbody tr'). attr ('bgcolor', 'red ');
} Else {
$ ('# Table tbody input [type = checkbox]'). prop ('checked', false );
$ ('# Table tbody tr'). attr ('bgcolor',' # fff ');
}
});
}

6.2/6.3,
Function addClass (){
$ ('# Table tbody input [type = checkbox]'). click (function (){
If ($ (this). prop ('checked ')){
$ (This ). parent ("td "). parent ("tr "). attr ('bgcolor', 'red'); // search for tr: $ (). parent ('td '). parent ('tr ')
} Else {
$ (This). parent ("td"). parent ("tr"). attr ('bgcolor', 'white ');
}
If ($ ('# table tbody tr'). length =$ (' # table tbody input [type = checkbox]: checked'). length ){
$ ('# Table thead input [type = checkbox]'). prop ('checked', true );
} Else {
$ ('# Table thead input [type = checkbox]'). prop ('checked', false );
}
});
}

7.1,
Function ajaxqq (){
$. Ajax ({
Type: 'post ',
Url: 'a.html ',
Data :{
Username: 'King' // parameters {}
}
});
}

7.2/7.3,
Function jxJsonData (){
Var jsonData = {"userList": [{"id": "1", "name": "Player", "age": "18" },{ "id ": "2", "name": "Player 2", "age": "18" },{ "id": "3", "name": "Player 3 ", "age": "18"}], "pageInfo": ["aa", "bb", "cc"]};
Var htmls = "<table> ";
$. Each (jsonData. userList, function (index, value) {// Iteration
Htmls = htmls + "<tr> <td>" + value. id + "</td> <td>" + value. name + "</td> <td>" + value. age + "</td> </tr> ";
});
Htmls = htmls + "</table> ";
$ (Htmls). appendTo ("body ");

Var pages = "";
$. Each (jsonData. pageInfo, function (index, value ){
Pages = pages + index + ":" + value + ",";
});
$ ("<P>" + pages + "</p>"). appendTo ("body ");
}

8.1,
Function ssUL (){
$ ("Ul> li> a"). next ("ul"). hide ();
$ ("Ul> li> a"). click (function (){
$ (This). next ("ul"). toggle (); // hide or display the toggle Function
});
}

8.2,
Function openWindow (){
$ ("<Iframe id = 'iframename' name = 'iframename' style = 'width: 160; height: 160; '> </iframe> "). appendTo ("body ");
$ ('Ul li A'). on ('click', function (){
$ (This ). attr ('target', 'iframename'); // The hyperlink content is opened in iframe. 1. Add the target attribute to the hyperlink. The value is the name of iframe. 2. Add the src value to iframe.
$ ('# Iframename'). attr ('src', $ (this). attr ('href '));
});
}

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.