1

I am fairly new to jQuery and need to cut some lines of code by writing a function that cycles through 3 separate variables. Below is my attempt to describe this (note that the objects work fine on their own, I just a function to cycle through the custom parameters: TYPE, POSITION AND RANK):

//TYPE: e, br, ie
//POSITION: l, r
//RANK: 1, 2, 3, 4, 5

//my script starts here
var TYPEPOSITIONRANKname = "label";
var TYPEPOSITIONRANKvalue = "percentage";
var TYPEPOSITIONRANKimg = "imgurl";
$("#statsTYPE .numberRANKranked .infobox_POSITION h3 span").text(TYPEPOSITIONRANKname);
$("#TYPEPOSITIONRANK img").attr({
    alt: TYPEPOSITIONRANKname,
    src: TYPEPOSITIONRANKimg
});
var TYPEPOSITIONRANKinter = $("#statsTYPE .numberRANKranked .infobox_POSITION p").text().replace(/[^0-9]+/g, "");
var TYPEPOSITIONRANKheight = parseInt(TYPEPOSITIONRANKinter, 10) /10 + 5;
$("#TYPEPOSITIONRANK").height(TYPEPOSITIONRANKheight + "%");

The words in all CAPS are my "parameters". In the example below, TYPE=e, POSITION=l and RANK=1:

var el1name = "label";
var el1value = "percentage";
var el1img = "imgurl";
$("#statse .number1ranked .infobox_l h3 span").text(el1name);
$("#el1 img").attr({
    alt: el1name,
    src: el1img
});
var el1inter = $("#statse .number1ranked .infobox_l p").text().replace(/[^0-9]+/g, "");
var el1height = parseInt(el1inter, 10) /10 + 5;
$("#el1").height(el1height + "%");
4

0 回答 0