如何制作交互式 HTML 表单,示例:
<select name="command">
<option value="send">Send</option>
<option value="cancel">Cancel</option>
</select>
<!--
I want the following text input hidden by default,
but active only if option "Cancel" is selected
-->
<input type="text" name="cancel_reason" id="needreason">
我希望“cancel_reason”输入字段默认隐藏,如果之前选择了下拉选项“Cancel”则显示,否则它应该保持隐藏状态。
最佳答案
$('select[name=command]').change(function(){
if($(this).val() == 'cancel')
{
$('#needreason').show();
}
else
{
$('#needreason').hide();
}
});
关于php - 使用 Javascript 的交互式 HTML 表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8148269/