var Items var Targets var Locations adding document ready function aja

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var Items;
var Targets;
var Locations;
//adding
$(document).ready(function() {
$.ajax({ type: "GET", url: "Item.xml", dataType: "xml", async: false, success: function (xml) {
Items= xml.getElementsByTagName("ITEM");
}
});
$.ajax({ type: "GET", url: "Target.xml", dataType: "xml", async: false, success: function (xml) {
Targets= xml.getElementsByTagName("TARGET");
}
});
$.ajax({ type: "GET", url: "Location.xml", dataType: "xml", async: false, success: function (xml) {
Locations= xml.getElementsByTagName("LOCATION");
}
});
$(".item").click(function() {
var check = $(this).attr('id');
for(var i=0;i<Items.length;i++)
{
var id=Items[i].getElementsByTagName("ID")[0];
if(check==id.childNodes[0].nodeValue){
var icon=Items[i].getElementsByTagName("IMG")[0];
$("#Interface").append("<img class="+"icon"+" id="+id.childNodes[0].nodeValue+" "+icon.childNodes[0].nodeValue+">");/*Добавляем иконку с id*/
}
}
});
$(".target").click(function() {
var t=$(this).attr('id');
$(".icon").click(function() {
var ico = $(this).attr('id');
for(var i=0;i<Targets.length;i++)
{
var icotest=Targets[i].getElementsByTagName("ID")[0];
if(t==icotest.childNodes[0].nodeValue){
$(this).remove();
}
}
});
});
});
//