在 javascript 中填写选项列表时遇到问题



我有一个按钮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;
}

这是填充模板"播放"选项的部分

显示器的调用是"<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>

change line xmlDoc.documentElement.appendChild(newPlay); to xmlDoc.getElementsByTagName("plays")[0].appendChild(newPlay);

在附加新创建的元素标签之前需要获取它

相关内容

  • 没有找到相关文章

最新更新