これは私には気が遠くなるようなものです。他のスタック オーバーフローから見たところ、これは正しいように思えます。とにかく、私は選択ボックスを持っています。それが変更されると、ボックスが表示されるはずです。ただし、代わりに 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>