0

这让我难以置信。从我从另一个堆栈溢出中看到的情况来看,这似乎是正确的。无论如何,我有一个选择框,当它改变它应该显示框可见。但是,我得到了 TypeError: Cannot read property 'style' of undefined 。是什么赋予了?

var consignedComps    = document.getElementsByName("ConsignedComponent")[pos];
if(type == "M") {
consignedComps.style.visibility="visible"; //where it throws the error
}

xsl 代码:

        <span id="ConsignedComponent" align="center">
                <xsl:attribute name="style"><xsl:choose><xsl:when test="Type = 'M' or Type = 'V' or Type='F'">visibility:visible</xsl:when><xsl:otherwise>visibility:hidden</xsl:otherwise></xsl:choose></xsl:attribute>
                <font face="verdana" size="2">
                    <input type="hidden" name="ConsignedChk" id="ConsignedChk">
                        <xsl:choose>
                            <xsl:when test="Consigned = 'true' or Consigned = 'TRUE' or Type = 'V'">
                                <xsl:attribute name="value">true</xsl:attribute>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:attribute name="value">false</xsl:attribute>
                            </xsl:otherwise>
                        </xsl:choose>
                    </input>
                    <input type="checkbox" name="Consigned" id="Consigned" value="true" >
                        <xsl:if test="Consigned = 'true' or Consigned = 'TRUE' or Type = 'V'">
                            <xsl:attribute name="checked">true</xsl:attribute>
                        </xsl:if>
                        <xsl:if test="Type = 'V'">
                            <xsl:attribute name="disabled">true</xsl:attribute>
                        </xsl:if>
                        <xsl:attribute name="onchange">
                            <xsl:text>setConsignedChk(</xsl:text><xsl:value-of select="position()"/><xsl:text>,</xsl:text><xsl:text>this.checked);</xsl:text>
                        </xsl:attribute>                            
                        <xsl:attribute name="onClick">
                            <xsl:text>enableAggregation(</xsl:text>
                            <xsl:value-of select="position()-1"/>
                            <xsl:text>);</xsl:text>
                        </xsl:attribute>
                    </input>
                </font>
            </span>
4

0 回答 0