我以爲我有這個想法,但我錯了。我有一個xsl表單,我希望在表單上選擇或存在特定值時切換或顯示/隱藏某個部分。我僅限於JavaScript,我感謝所有幫助。用Javascript顯示/隱藏DIV部分onchange和onload
- 當用戶選擇選項,隱藏的div部分節目和
- 當形式被加載並且該值存在時,DIV部分顯示
下面是示例HTML我想從工作想出解決辦法:
<select name="sbFruit" id="sbFruit" style="display:none;" title="Select your Fruit">
<xsl:variable name="sbFruit" select="Fruit" />
<xsl:for-each select="document('FRUIT_Lookups.xml')/lookups/FruitTypes/Fruit">
<xsl:variable name="optFruit" select="value" />
<option>
<xsl:if test="$sbFruit = $optFruit">
<xsl:attribute name="selected">true</xsl:attribute>
</xsl:if>
<xsl:attribute name="value">
<xsl:value-of select="value"/>
</xsl:attribute>
<xsl:value-of select="value"/>
</option>
</xsl:for-each>
</select>
<!-- Toggled Group when 'sbFruit' = Orange -->
<div id="AppleSubGroup" name="AppleSubGroup" style="display: none;>"
<label id="Orange_Fresh">Is the Orange Fresh?</label>
<input name="Fresh" type="radio" value="Yes" />Yes
<input name="Fresh" type="radio" value="No" />No
<br />
<label id="Orange_moldy">Is the Orange moldy?</label>
<input name="Red" type="radio" value="Yes" />Yes
<input name="Red" type="radio" value="No" />No
</div>
XML水果的選擇:
Apple
Blueberry
Orange
Pear
或簡單的HTML版本:
<select id="sbFruit" name="sbFruit">
<option>Apple</option>
<option>Blueberry</option>
<option>Orange</option>
<option>Pear</option>
</select>
<!-- Toggled Group when 'sbFruit' = Orange -->
<div id="AppleSubGroup" name="AppleSubGroup" style="display: none;>"
<label id="Orange_Fresh">Is the Orange Fresh?</label>
<input name="Fresh" type="radio" value="Yes" />Yes
<input name="Fresh" type="radio" value="No" />No
<br />
<label id="Orange_moldy">Is the Orange moldy?</label>
<input name="Red" type="radio" value="Yes" />Yes
<input name="Red" type="radio" value="No" />No
</div>
感謝您的幫助!
嘗試更改要顯示或隱藏的div的顯示類(塊/無) –