早上好,我遇到問題切換基於下拉選擇顯示和隱藏哪些元素。我嘗試了很多東西,但看不到它的工作。下面是HTML代碼的樣本,我使用:顯示錶格基於下拉選擇使用Javascript
UPDATE: This is the new code that I tried out, but still nothing is working
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
$(document).ready(function() {
$('#TypeOfChange').change(function() {
if ($(this).val() == 'Option 1') {
$('#Table1').css({'display': 'block'});
$('#RequestTypeTableTR').css({'display': 'block'});
} else {
$('#Table1').css({'display': 'none'});
$('#RequestTypeTableTR').css({'display': 'none'});
}
if ($(this).val() == 'Option 2') {
$('#Table2').css({'display': 'block'});
$('#RequestTypeTableTR').css({'display': 'block'});
} else {
$('#Table2').css({'display': 'none'});
$('#RequestTypeTableTR').css({'display': 'none'});
}
});
});
</script>
</head><body>
<form id="form1" name="form1" method="POST" action="<%=MM_editAction%>">
<table border="0" class="form">
<tr valign="baseline" class="clear">
<td align="right" valign="middle" nowrap="nowrap" class="style8"><h2>General Information</h2></td>
<td valign="baseline"> </td>
</tr>
<tr valign="baseline" class="clear">
<td align="right" valign="top" nowrap="nowrap" class="style9">
<p>*Request Type:</p>
</td>
<td valign="top" class="style8">
<p>
<span id="spryselect5">
<label>
<select name="TypeOfChange" id="TypeOfChange">
<option value="Please Select" selected="selected">Please Select</option>
<option value="Option 1">Option 1</option>
<option value="Option 2">Option 2</option>
<option value="Option 3">Option 3</option>
<option value="Option 4">Option 4</option>
<option value="Option 5">Option 5</option>
</select>
</label>
<span class="selectInvalidMsg">Please select a valid item.</span><span class="selectRequiredMsg">Please select an item.</span>
</span>
<span class="style1">*</span>
</p>
</td>
</tr>
<tr style="display:none" id="RequestTypeTableTR" valign="baseline" class="clear">
<td valign="middle" nowrap="nowrap"> </td>
<td valign="baseline">
<table style="display:none" id="Table1" width="100%">
<tr>
<td Colspan="2" align="right" valign="middle" nowrap="nowrap" class="style8"><h2>Patient Safety1</h2></td>
</tr>
</table>
<table style="display:none" id="Table2" width="100%">
<tr>
<td Colspan="2" align="left" valign="middle" nowrap="nowrap" class="style8"><h2>Patient Safety2</h2></td>
</tr>
</table>
</td>
</tr>
</table></FORM>
您的'選項1'代碼不在'change'函數中。 – callback