jsp:
<style>
ul{}
ul li{list-style-type:none;padding-left:12px;width:200px;}
.plus{background:url(img/tree_plusL.gif) no-repeat left center;}
.minus{background:url(img/tree_minusL.gif) no-repeat left center;}
</style>
<script>
function loadPage(){
var modelLi;
$("ul li").click(function(){
var target=$(this);
if(target.attr("class")=="plus"){
target.attr("class","minus");
if(target.next().eq(0).attr("outerHTML")!=undefined&&target.next().eq(0).attr("nodeName").toLowerCase()=="ul"){
target.next("ul").eq(0).show();
}else{
$.get("/${projectName}/basetree/basetree.do?method=schOrganChildren",function(data){
if(data.length >1){
target.after("<ul></ul>");
var nodeArr = data.split("!");
var tli;
for(var i=0;i<nodeArr.length;i++){
tli=modelLi.clone(true);
node=eval("("+nodeArr[i]+")");
tli.attr("innerHTML",node.name);
if(target.attr("class")=="minus"){
target.next("ul").eq(0).append(tli);
}
}
}
});
}
}else{
target.attr("class","plus");
if(target.next().eq(0).attr("outerHTML")!=undefined&&target.next().eq(0).attr("nodeName").toLowerCase()=="ul"){
target.next("ul").eq(0).hide();
}
}
});
modelLi=$("ul li").eq(0).clone(true);
}
</script>
<body>
<ul>
<li class="plus">
石家庄
</li>
</ul>
</body>
action:
public ActionForward schOrganChildren(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
response.setHeader("Cache-Control", "no-cache,must-revalidate");
String str="{name:'市区行政机构',id:'1'}!{name:'河西区',id:'2'}!{name:'河东区',id:'3'}";
PrintWriter out;
try {
request.setCharacterEncoding("UTF-8");
response.setContentType( "text/html" );
response.setCharacterEncoding( "UTF-8" );
str= java.net.URLDecoder.decode(str,"UTF-8");
out = response.getWriter();
out.print(str);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
解答: <div>***</div>
xx.innnerHTML=***
xx.outterHTML=<div>***</div>
target是当前对象
target.next("ul")是jquery的一个对象
target.next("ul").eq(0)取的是对象的第一个元素
modelLi=$("ul li").eq(0).clone(true);
.clone(true);是复制的意识,这里是把jquery的li对象复制给modelLi。 |