以下代码有效,但我遇到以下问题:
jQuery的:
<script type="text/javascript">
$(document).ready(function()
{
$.viewMap = {
'0' : $([]),
'6' : $('#result1'),
'7' : $('#result2'),
'8' : $('#result3'),
'9' : $('#result4'),
'10': $('#result5'),
'11': $('#result6')
};
$('#mainWidgetName').change(function()
{
// hide all
$.each($.viewMap, function() {$(this).hide(); });
// show current
$.viewMap[$(this).val()].show();
});
});
</script>
HTML:
<table class="simple">
<?php echo $form['mainWidgetName']->renderRow(); ?>
<tr id="result1" style="display:none"><th><?php echo $form[‘widgetName1’]->renderLabel() ?></th><td><?php echo $form['widgetName1']->render(); ?></td></tr>
<tr id="result2" style="display:none"><th><?php echo $form[‘widgetName2’]->renderLabel() ?></th><td><?php echo $form['widgetName2']->render(); ?>t</td></tr>
<tr id="result3" style="display:none"><th><?php echo $form[‘widgetName3’]->renderLabel() ?></th><td><?php echo $form['widgetName3']->render(); ?></td></tr>
<tr id="result4" style="display:none"><th><?php echo $form[‘widgetName4’]->renderLabel() ?></th><td><?php echo $form['widgetName4']->render(); ?></td></tr>
<tr id="result5" style="display:none"><th><?php echo $form[‘widgetName5’]->renderLabel() ?></th><td><?php echo $form['widgetName5']->render(); ?></td></tr>
<tr id="result6" style="display:none"><th><?php echo $form[‘widgetName6’]->renderLabel() ?></th><td><?php echo $form['widgetName6']->render(); ?></td></tr>
<tr><td></td><td><input type="submit" value="Submit" /></td></tr>
</table>
答案 0 :(得分:0)
我发现了一个很棒的插件,可以实现我想要的结果:
http://www.erichynds.com/jquery/jquery-related-dependent-selects-plugin/