$(d).find('location#sydney')
. #sydney value sydney, ID. HTML id="..." ID DOCTYPE. XML DOCTYPE, id="..." ID. , getElementById('sydney') , #sydney .
, , find(), jQuery "Sizzle JavaScript selector matcher", id="...", HTML. Sizzle , . location[id=sydney] XML-.
var sydneyuv = sydneyuv += '<span>' + uvindex + '</span>' ;
. +=, - sydneyuv, sydneyuv.
, HTML . , uvindex HTML? (, , , , , .) HTML- HTML XSS. DOM, text() attr() jQuery, : var $sydneyuv= $('<span/>', {text: uvindex});, .
, - .
. :
var towns= ['sydney', 'melbourne', 'brisbane', 'perth', 'adelaide', 'darwin'];
var uvlevels= [
{uvlevel: 2, risk: 'Low', curcon: 'You can safely stay outdoors and use an SPF 15 moisturiser.'},
{uvlevel: 5, risk: 'Moderate', curcon: 'Wear protective clothing outdoors and use an SPF 15 or SPF 30 moisturiser.'},
{uvlevel: 7, risk: 'High', curcon: 'Wear protective clothing, limit your time outdoors and use an SPF 30 moisturiser.'},
{uvlevel: 10, risk: 'Very high', curcon: 'Use caution, limit exposure to the sun and use an SPF 30 moisturiser.'},
{uvlevel: 20, risk: 'Extreme', curcon: 'Use extreme caution, avoid exposure to the sun and use an SPF 30 moisturiser.'},
{uvlevel: null, risk: 'Unavailable', curcon: 'Information is currently unavailable.'}
];
:
$.each(towns, function() {
var $location= $(d).find('location[id='+this+']');
var uv= $location.find('index').text();
var shorttown= this.slice(0, 3);
$('#uv-'+shortttown).empty().append($('<span/>', {text: uv}));
$.each(uvlevels, function() {
if (this.uvlevel===null || uv<=this.uvlevel) {
$('#risk-'+shorttown).text(this.risk);
$('#curcon-'+shorttown).text(this.curcon);
return false;
}
});
});
, -, .
( HTML, shorttown).