javascript - 错误: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>
解决方案
推荐阅读
- azure - 天蓝色上 blob 的放置和发布方法返回 404 指定的资源不存在。
- spring - Spring Data Jpa 自定义存储库未找到任何属性
- ember.js - Ember.js - ember-pikaday 不解析美国日期?
- python - Archlinux:pip:ImportError:无法导入名称“请求”
- sql - 区分全额退款与部分退款
- business-process-management - 投资银行中后台典型IT项目
- angular - 预期的“样式”是一个字符串数组,角度为 5
- vba - 宏适用于我的 Excel,但不适用于其他人
- google-cloud-firestore - Firestore 更新文档对象字段中的多个属性
- python - 从 csv 文件导入权重:层权重形状 (672, 7) 与提供的权重形状 (1, 1, 672, 7) 不兼容