带checkbox的xml 树双击事件,如何设置CHECKED属性?

killerdanny 2004-09-06 05:55:06
//tree.xml

<?xml version="1.0"?>
<tree>
<entity id="e1" >
<description>Customers</description>
<oncontextmenu></oncontextmenu>
<image>images/book.gif</image>
<imageOpen>images/bookOpen.gif</imageOpen>
<contents>
<entity id="e2" >
<description>Microsoft</description>
<image>images/book.gif</image>
<imageOpen>images/bookOpen.gif</imageOpen>
<onClick>danny()</onClick>
<contents>
<entity id="e3" >
<description>Orders</description>
<image>images/book.gif</image>
<imageOpen>images/bookOpen.gif</imageOpen>
<onClick></onClick>
<contents/>
</entity>
</contents>
</entity>
<entity id="e4" >
<description>IBM</description>
<image>images/book.gif</image>
<imageOpen>images/bookOpen.gif</imageOpen>
<onClick>displayCustomer(12346)</onClick>
<contents>
<entity id="e5" >
<description>Orders</description>
<image>images/book.gif</image>
<imageOpen>images/bookOpen.gif</imageOpen>
<onClick></onClick>
<contents/>
</entity>
</contents>
</entity>
<entity id="e6" >
<description>Sun Microsystems</description>
<image>images/book.gif</image>
<imageOpen>images/bookOpen.gif</imageOpen>
<onClick>displayCustomer(12347)</onClick>
<contents>
<entity id="e7" >
<description>Orders</description>
<image>images/book.gif</image>
<imageOpen>images/bookOpen.gif</imageOpen>
<onClick></onClick>
<contents>
<entity id="e8" >
<description>#12345</description>
<image>images/paper.gif</image>
<imageOpen>images/paper.gif</imageOpen>
<onClick></onClick>
<contents/>
</entity>
<entity id="e9" >
<description>#12346</description>
<image>images/paper.gif</image>
<imageOpen>images/paper.gif</imageOpen>
<onClick></onClick>
<contents/>
</entity>
</contents>
</entity>
</contents>
</entity>
<entity id="e10" >
<description>Oracle</description>
<image>images/book.gif</image>
<imageOpen>images/bookOpen.gif</imageOpen>
<onClick>displayCustomer(12348)</onClick>
<contents>
<entity id="e11" >
<description>Orders</description>
<image>images/book.gif</image>
<imageOpen>images/bookOpen.gif</imageOpen>
<onClick></onClick>
<contents/>
</entity>
</contents>
</entity>
</contents>

</entity>
<entity id="e12">
<description>Reports</description>
<oncontextmenu></oncontextmenu>
<image>images/book.gif</image>
<imageOpen>images/bookOpen.gif</imageOpen>
<contents>
<entity id="e13">
<description>Income</description>
<oncontextmenu></oncontextmenu>
<image>images/paper.gif</image>
<imageOpen>images/paper.gif</imageOpen>
<contents>
</contents>
</entity>
<entity id="e14">
<description>Expenses</description>
<oncontextmenu></oncontextmenu>
<image>images/paper.gif</image>
<imageOpen>images/paper.gif</imageOpen>
<contents>
</contents>
</entity>
</contents>
</entity>
</tree>

/////////////////////////
//tree.xsl
/////////////////////////
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" language="JavaScript">
<xsl:template match="tree">
<xsl:apply-templates select="entity"/>
</xsl:template>
<xsl:template match="entity">
<div onclick="window.event.cancelBubble = true;clickOnEntity(this);" onselectstart="return true" ondragstart="return true"
>
<xsl:attribute name="image"><xsl:value-of select="image"/></xsl:attribute>
<xsl:attribute name="imageOpen"><xsl:value-of select="imageOpen"/></xsl:attribute>
<xsl:attribute name="open">false</xsl:attribute>
<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
<xsl:attribute name="open">false</xsl:attribute>
<xsl:attribute name="STYLE">
padding-left: 20px;
cursor: hand;
<xsl:if expr="depth(this) > 2">
display: none;
</xsl:if>
</xsl:attribute>
<table border="0" cellspacing="0" cellpadding="0">
<tr >
<td valign="middle">
<img border="0" id="image">
<xsl:attribute name="SRC">
<xsl:value-of select="image"/>
</xsl:attribute>
</img>
</td>
<td valign="middle">
<xsl:if expr="depth(this) > 2">
<input type="checkbox">
<xsl:attribute name="name"><xsl:value-of select="description"/></xsl:attribute>
<xsl:attribute name="value">ON</xsl:attribute>
<xsl:attribute name="onClick">return false</xsl:attribute>
</input>
</xsl:if>
</td>
<td valign="middle" nowrap="true" CLASS="bOut1" ONMOUSEOVER="swapClass(this, 'bOver')" ONMOUSEOUT="swapClass(this, 'bOut1')" >
<xsl:attribute name="STYLE">
padding-left: 7px;
font-family: Verdana;
font-size: 11px;
font-color: black;
</xsl:attribute>
<p ondblclick ="danny(this)">
<xsl:value-of select="description"/></p></td>
</tr>
</table>
<xsl:apply-templates select="contents/entity"/>
</div>
</xsl:template>
</xsl:stylesheet>

/////////////////////////
//tree.js
/////////////////////////
function initialize() {
var xmlDoc
var xslDoc

xmlDoc = new ActiveXObject('Microsoft.XMLDOM')
xmlDoc.async = false;

xslDoc = new ActiveXObject('Microsoft.XMLDOM')
xslDoc.async = false;

xmlDoc.load("tree/tree.xml")
xslDoc.load("tree/tree.xsl")

folderTree.innerHTML = xmlDoc.documentElement.transformNode(xslDoc)
}

function clickOnEntity(entity) {
if(entity.open == "false") {
expand(entity, true);
//alert(entity.);
//alert(entity.all.["table"]);
}
else {
collapse(entity)
}
window.event.cancelBubble = true
}
function danny(entity){

//此处处理双击事件
//怎么访问到树节点上的CHECKBOX?

}
//alert(entity.childNodes(0).baseName + ".value");}
function expand(entity) {
var oImage

oImage = entity.childNodes(0).all["image"]
oImage.src = entity.imageOpen

for(i=0; i < entity.childNodes.length; i++) {
if(entity.childNodes(i).tagName == "DIV") {
entity.childNodes(i).style.display = "block"
}
}
entity.open = "true"
}

function collapse(entity) {
var oImage
var i

oImage = entity.childNodes(0).all["image"]
oImage.src = entity.image

// collapse and hide children
for(i=0; i < entity.childNodes.length; i++) {
if(entity.childNodes(i).tagName == "DIV") {
if(entity.id != "folderTree") entity.childNodes(i).style.display = "none"
collapse(entity.childNodes(i))
}
}
entity.open = "false"
}

function expandAll(entity) {
var oImage
var i

expand(entity, false)

// expand children
for(i=0; i < entity.childNodes.length; i++) {
if(entity.childNodes(i).tagName == "DIV") {
expandAll(entity.childNodes(i))
}
}
}
...全文
209 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
killerdanny 2004-09-07
  • 打赏
  • 举报
回复
已经搞定了,我把ondblclick ="danny(this)"放在TR里面了
  • 打赏
  • 举报
回复
或者在你调用函数中把<checkbox>的id传值过来也好办啊
或者是document.getElementsTagName("checkbox")
killerdanny 2004-09-07
  • 打赏
  • 举报
回复
upup
lakesea 2004-09-06
  • 打赏
  • 举报
回复
太长了,我也不懂xml,帮你顶
mickeylm 2004-09-06
  • 打赏
  • 举报
回复
帮你顶
  • 打赏
  • 举报
回复
你为什么要在<p>中返回判断呢??
内容概要:本文围绕“基于共享储能服务的智能楼宇双层优化配置”展开研究,提出了一种结合上层共享储能配置优化与下层楼宇内部能源调度优化的双层协同模型,通过Matlab代码实现,旨在提升智能楼宇在复杂能源环境下的运行效率与经济性。研究充分考虑光伏出力、负荷需求等不确定性因素,引入多维核密度估计、场景生成与削减等技术进行不确定性建模,并融合需求响应、微电网调度等先进理念,实现了对综合能源系统中储能资源的高效配置与动态调控,具有较强的理论深度与工程应用价值。; 适合人群:具备电力系统、可再生能源、优化算法或综合能源系统等相关背景,从事科研、工程应用或课题研究的研发人员、研究生及高年级本科生。; 使用场景及目标:①应用于智能楼宇、园区微电网、虚拟电厂等场景中的储能规划与运行优化;②支撑高水平学术论文(如EI/SCI)的复现、课题申报、毕业设计及实际项目的双层优化建模与求解实践。; 阅读建议:建议结合提供的Matlab代码进行实操演练,重点理解双层优化架构的设计逻辑、求解策略(如Benders分解、主从博弈等)及不确定性处理方法,同时可参考文中关联技术(如场景生成、需求响应)拓展研究思路与应用场景。

87,987

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧