質問編集履歴
1
コードの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -24,4 +24,42 @@
|
|
24
24
|
ご回答いただけると助かりますm(._.)m
|
25
25
|
|
26
26
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
27
|
-
jQueryの$.ajaxを使用してxmlファイルを読み込もうと考えています。
|
27
|
+
jQueryの$.ajaxを使用してxmlファイルを読み込もうと考えています。
|
28
|
+
|
29
|
+
|
30
|
+
###追記
|
31
|
+
コメントありがとうございます_(._.)_
|
32
|
+
|
33
|
+
###該当のソースコード
|
34
|
+
```xml
|
35
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
36
|
+
<info>
|
37
|
+
<item type="type01">
|
38
|
+
<id>type01</id>
|
39
|
+
<name>test1</name>
|
40
|
+
<texture_src>assets/picture1.png</texture_src>
|
41
|
+
</item>
|
42
|
+
<item type="type02">
|
43
|
+
<id>type02</id>
|
44
|
+
<name>test2</name>
|
45
|
+
<texture_src>assets/picture2.png</texture_src>
|
46
|
+
</item>
|
47
|
+
</info>
|
48
|
+
|
49
|
+
```
|
50
|
+
|
51
|
+
上記のように<item>にtypeを付与し、クリックするボタンそれぞれのid属性にtypeの値を持たせ、
|
52
|
+
|
53
|
+
###該当のソースコード
|
54
|
+
```jquery
|
55
|
+
$(xml).find("item").each(function(){
|
56
|
+
if($(this).attr("type") == "type01"){
|
57
|
+
var src = $(this).children("texture_src").text();
|
58
|
+
}
|
59
|
+
});
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
上記のように、typeごとに子要素を探しに行く。といった感じです。
|
64
|
+
|
65
|
+
色々試してみてうまく動いた!という感じですので、何か誤りがあるかもしれませんが...
|