php - 使用 Javascript 的交互式 HTML 表单

标签 php javascript jquery html forms

如何制作交互式 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/

相关文章:

javascript - opencart 2.0 未定义 gaq

php - fatal error : Uncaught exception 'PHPExcel_Exception'

javascript - 添加事件监听器后覆盖变量

javascript - 如何使用存储在亚马逊网络服务上的 jquerycropper 编辑图像?

jquery - 如何在 jQuery 中存储 JSON 响应?

php - WooCommerce - 自动添加奖励产品

php - PHP 中的突出显示搜索关键字无法正确突出显示

javascript - JQuery Mobile 滚动时隐藏地址栏

javascript - 如何使用 KnockoutJs Binding 在 moment.js 中将日期转换为其他格式?

JQuery循环.mouseenter动画不停止