jquery gets the Li array from the page, deleting the key that is not in the array

Source: Internet
Author: User

Application Scenarios:

Gets the value of the page Li key below, added to the ARR array

Delete the value of the model that is not in the ARR array.

Example code:

var getsalemodels = function (brand_id) {

if (brand_id) {
var li = $ (". Pinpai-chexing" +brand_id+ "Li");
var arr = new Array ();
if (Li.length > 0) {
Li.each (function (index, Element) {

Arr.push (Element). Children ("a"). attr ("Data-value"));
});
}
}

return arr;
}

Application

Get car
var Getmodel = function (ID) {

var arr = getsalemodels ($ ("#brand_id"). attr ("Data-value"));
$.getjson ("/interface/carbase/gettuangoumodels/", {id:$ ("#brand_id"). attr ("Data-value")},function (JSON) {
var models = $ (". Models");
var option = "";
$ (models). Find ("Li"). empty (); Clear the original options
if (JSON) {
$.each (Json.data,function (Index,array) {

Removal of discontinued models
if ($.inarray (array[' model_id '],arr)!=-1) {
if (!index) {
$ ("#model_id"). attr ("Data-value", array[' model_id ']);
$ ("#model_id"). Text (array[' model ');
}
Option + = "<li data-value= '" +array[' model_id ']+ "'";
Option + = ">" +array[' Model ']+ "</li>";
}
});
Models.append (option);
}
});
return false;
}

jquery gets the Li array from the page, deleting the key that is not in the array

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.