我有一个 xml 文件:-
<child_2 entity_id="2" value="Root" parent_id="1">
<child_4 entity_id="4" value="Activities" parent_id="2">
<child_10066 entity_id="10066" value="Physical1" parent_id="4">
<child_10067 entity_id="10067" value="Cricket" parent_id="10066">
<child_10068 entity_id="10068" value="One Day" parent_id="10067"/>
</child_10067>
</child_10066>
<child_10069 entity_id="10069" value="Test2" parent_id="4"/>
<child_10070 entity_id="10070" value="Test3" parent_id="4"/>
<child_10071 entity_id="10071" value="Test4" parent_id="4"/>
<child_10072 entity_id="10072" value="Test5" parent_id="4"/>
<child_5 entity_id="5" value="Physical" parent_id="4"/>
</child_4>
</child_2>
这是我的完整代码:-
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
function load()
{
$.ajax({ type: "GET",
async: false,
url: "reg.xml",
dataType: "xml",
success: function(xml){
makeHTML(xml,'child_4', $('ul'));
}
});
}
function makeHTML(xml,parent, $ul) {
$(xml).find(parent).children().each(function() {
var $node = $(this) ;
var $li = $('<li></li>').html( $node.attr('value') );
$ul.append( $li );
if ( $node.children().length > 0 ) {
$childUl = $('<ul></ul>').hide();
$ul.append( $childUl );
// toggle hide and show
$li.click( function(){
if( $(this).next().css('display') == 'none') {
$(this).next().show();
} else {
$(this).next().hide();
}
});
makeHTML( $node.attr('tagName'), $childUl );
}
});
}
</script>
单击不起作用...
请帮助我解决此问题...