jquery-Problem Solving

Source: Internet
Author: User

1, var v = $ ('. Summer-input:input '). Val (); Get input by class

2, var v = $ (' input[name=user\\.name] '). Val (); Escape band. The name escape \ \

3, var v = $ (' Input:eq ( -2) '). Val (); Gets the countdown to the second INPUT element in the div to write a negative number

4. Object [] $ (' div > Span '). The HTML () is the one//div >span for the sub-element under the Div; Div span is the div in all the

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); The checkbox determines whether the check is selected, $ (). 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 up TR: $ (). Parent (' TD '). Parent (' TR ')
}else{
$ (this). The 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 '//Connect parameter {}
}
});
}

7.2/7.3,
function Jxjsondata () {
var jsondata = {"UserList": [{"id": "1", "name": "Player", "Age": "},{", "id": "2", "Name": "Player 2", "Age": "},{", "id": "3", "name" : "Player 3", "Age": "+"}], "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 (); The toggle function hides or displays
});
}

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 '); Content of hyperlinks Open in IFrame 1, add the target property to the hyperlink, value the name 2 of the IFRAME, add src value to the IFRAME
$ (' #iframename '). attr (' src ', $ (this). attr (' href '));
});
}

jquery-Problem Solving

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.