[javascript] view plain copy
$(document).ready(function(){
data=$.ajax({url:"获取json链接地址",async:false});
data2 = data.responseText;
var data2 = JSON.parse(data2);
var data3 =data2.gamelists;
data3.forEach(function(e){
$("#list1_info").append("<li><div class=\"game_img\"><a href="+decodeURIComponent(e.opengame_url)+"><img src=" + decodeURIComponent(e.icon_url) + "></a></div><div class=\"game_content\"><h1><a href=/" + decodeURIComponent(e.opengame_url) + ">" + e.zh_name + "</a></h1><div class=\"star_w\"><p style=\"width:40%\"></p></div><span>人气:" + e.clicks + "</span><div class=\"game_cwz\">" + e.brief + "</div></div><div class=\"game_button\"><a href=" + decodeURIComponent(e.opengame_url) + ">开始游戏</a></div></li>");
})
});
[javascript] view plain copy
//纯Jquery
function tab_nav(nav){
$.getJSON("获取json链接地址", function (data) {
$.each(data.gamelists,function (i, item){
$("#list1_info").append("<li><div class=\"game_img\"><a href=" + decodeURIComponent(item.opengame_url) + "><img src=" + decodeURIComponent(item.icon_url) + "></a></div><div class=\"game_content\"><h1><a href=" + decodeURIComponent(item.opengame_url) + ">" + item.zh_name + "</a></h1><div class=\"star_w\"><p style=\"width:40%\"></p></div><span>人气:" + item.clicks + "</span><div class=\"game_cwz\">" + item.brief + "</div></div><div class=\"game_button\"><a href=" + decodeURIComponent(item.opengame_url) + ">开始游戏</a></div></li>");
});
});
}
1、remove()方法
[javascript]
view plain
copy
- $("ul li").click(function(){
- alert($(this).html());
- });
- var $li = $("ul li:eq(1)").remove();
- $li.appendTo("ul");
2、detach()方法
[javascript]
view plain
copy
- var $li = $("ul li:eq(1)").detach();
- $li.appendTo("ul");
3、empty()方法
[javascript]
view plain
copy
- var $li = $("ul li:eq(1)").empty();
- $li.appendTo("ul");
严格地讲,empty()方法并不是删除节点,而是清空节点,它能清空元素中的所有后代节点。
//删除子节点 $("#addInfos").children("#div").remove();
//增加子节点
$( "#text")[ 0]. outerHTML ;
$( "#addInfos"). append( $( "#text")[ 0]. outerHTML) ;
$( "#text")[ 0]. outerHTML ;
$( "#addInfos"). append( $( "#text")[ 0]. outerHTML) ;