首页 > 解决方案 > 错误:HTML / JQuery 更改选择时我无法清理输入

问题描述

我需要在更改选择的选项时删除已完成的字段:

选择时elemento_tipo,它启用加载输入elemento_valor,问题是当我elemento_tipo再次更改选项时,该字段elemento_valor保留输入的值。

我粘贴了部分代码。

<div class="row">
    <div class="form-group col-sm-8">
        <?php echo $fields['elemento_tipo']['label']; ?>
        <?php echo $fields['elemento_tipo']['form']; ?>
    </div>
</div>
<div class="row">
    <div class="form-group col-sm-2">
        <?php echo $fields['elemento_valor']['label']; ?>
        <?php echo $fields['elemento_valor']['form']; ?>
    </div>
    <div class="form-group col-sm-6">
        <?php echo $fields['elemento_secundario']['label']; ?>
        <?php echo $fields['elemento_secundario']['form']; ?>
    </div>
</div>
</div>

<script>
    $(document).ready(function() {
        $('#servicio_table').DataTable({
            language: {
                url: 'plugins/datatables/spanish.json'
            },
            dom: 't',
            paging: false,
            autoWidth: false,
            searching: false,
            ordering: false,
            scrollY: '400px',
        });

        $('#elemento_valor, #elemento_secundario').attr('disabled', true);
        $('#elemento_tipo').change(function() {
            $('#elemento_valor, #elemento_secundario').attr('disabled', true);
            $('#elemento_secundario')[0].selectize.disable();
            opcion = $(this).val();
            if (jQuery.inArray(opcion, ['3', '4']) != -1) {
                $('#elemento_valor').attr('disabled', false);
            }
            if (opcion === '5') {
                $('#elemento_secundario')[0].selectize.enable();
            }
        });
    });
</script>

标签: javascripthtmljquery

解决方案


推荐阅读