我有一个addPlay()
是一个按钮,过程的一部分是它将填充一个选项列表,但它没有这样做。
以下是从
调用的部分var gamelogElem=document.getElementById("gamelog");
var newPlay=xmlDoc.createElement("play");
var minIndex=document.getElementById("min").selectedIndex;
var secIndex=document.getElementById("sec").selectedIndex;
var actIndex=document.getElementById("action").selectedIndex;
var playerIndex=document.getElementById("player").selectedIndex;
var minute=document.getElementById("min").options[minIndex].text;
var second=document.getElementById("sec").options[secIndex].text;
var time=minute + ":" + second;
var playerOpt=document.getElementById("player").options;
var player=playerOpt[playerIndex].text;
var op = document.getElementById("player")
.options[document.getElementById("player").selectedIndex];
var optgroup = op.parentNode;
var team=optgroup.label;
var actionOpt=document.getElementById("action").options;
var action=actionOpt[actIndex].text;
// these values above are the ones that should be showing up and are in the play template
newPlay.setAttribute("time", time);
newPlay.setAttribute("player", player);
newPlay.setAttribute("team", team); // can't define
newPlay.setAttribute("action", action);
xmlDoc.documentElement.appendChild(newPlay);
gamelogElem = runTransform(xmlDoc,xsltDoc4);
这是runTransform
函数
function runTransform(xDoc, xsltDoc) {
var xProcessor = new XSLTProcessor();
xProcessor.importStylesheet(xsltDoc);
var resultDoc = xProcessor.transformToDocument(xDoc);
var serializer = new XMLSerializer();
var resultStr = serializer.serializeToString(resultDoc);
return resultStr;
}
以下是填充模板“play”中选项的部分
显示屏的调用是"<select name="actionlist" size="20">...</select>"
,您可以在下面看到它,并按照它调出上面设置的值。
<xsl:template match="plays">
<table class="actions">
<tr>
<th>Game Log</th>
</tr>
<tr>
<td>
<select name="actionlist" size="20">
<xsl:apply-templates select="play" />
</select>
</td>
</tr>
</table>
</xsl:template>
<xsl:template match="play">
<option>
[<xsl:value-of select="@time" />] <xsl:value-of select="@player" /> (<xsl:value-of select="@team" />) <xsl:value-of select="@action" />
</option>
</xsl:template>
答案 0 :(得分:0)
更改行xmlDoc.documentElement.appendChild(newPlay); to xmlDoc.getElementsByTagName(“plays”)[0] .appendChild(newPlay);
需要在添加之前获取新创建的元素标记