java如何设置“org”的第一个子级。w3c。多姆。元素`?
我有一个组织的根元素。w3c。多姆。element’类和我有一个方法,该方法根据条件设置脚本的名称,并创建一个scriptelement,并使用appendchild将该scriptelement作为rootelement的子节点插入。它将根元素和的属性(“onload”)设置为此脚本
但是我们知道appendchild总是插入一个节点作为最后一个子节点,我想知道是否有任何机制可以将此元素设置为rootelement的第一个子节点,因为在IE中,当我们第一次加载页面时,我会收到一条消息,即特定脚本未定义。下面给出的是代码片段
if ( bEnableMouseEvents )
{
String scriptName = "SvgScriptUtils";
if ( !bUsingPlugin )
scriptName = scriptName + "Native";
// insert external javascript driver for tooltips/navigation-mode/popups
rootSVG.setAttribute("contentScriptType", "text/ecmascript");
Element scriptElement = doc.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, SVGConstants.SVG_SCRIPT_TAG);
scriptElement.setAttribute("type", "text/ecmascript");
XlinkHref.set(scriptElement, "/scripts/" + scriptName + ".fs");
rootSVG.appendChild(scriptElement);
rootSVG.setAttribute("onload", scriptName + ".initMOS(evt)");
}
# 1 楼答案
试试
Node.insertBefore(Node newChild, Node refChild)
,其中refChild
将是您当前的第一个孩子(如果您不知道,可以通过调用Node.getFirstChild()
来获得)有关更多信息,请查看javadoc