javascript - 无法使选择禁用和启用
问题描述
当我分别单击编辑和保存按钮时,我想使文本和选择选项禁用和启用。在我的情况下,文本字段在点击时被禁用和启用,但选择下拉菜单没有被禁用和启用。在 javascript 中,我调用了该类来禁用和启用文本字段。如何进行选择。
$(document).ready(function() {
$('.editBtn').click(function() {
if ($('.editField').is('[readonly]')) { //checks if it is already on readonly mode
$('.editField').prop('readonly', false); //turns the readonly off
$('.editBtn').html('<span class="glyphicon glyphicon-floppy-disk"> </span>'); //Changes the text of the button
} else { //else we do other things
$('.editField').prop('readonly', true);
$('.editBtn').html('<span class="glyphicon glyphicon-pencil"> </span>');
}
});
});
HTML:
<select id="dept" class="form-control editField" required></select>
解决方案
由于您使用的是 jQuery,因此您可以这样做来启用选择:
$('.mySelect').prop('disabled', false); //enabled
这可以禁用选择:
$('.mySelect').prop('disabled', true); //disabled
推荐阅读
- spring - 基于 Spring MVC 的应用程序在尝试使用 https url 访问它时没有登陆到默认成功 url,但在基于 http 的 url 上工作正常
- java - 如何在 Android Studio 中使用导入的 .so 库代码?
- sql - 如何在 Oracle 中以同一列的两种类型聚合为中心?
- apache-spark - 为什么 spark 任务看起来像按顺序运行
- r - 在 rmarkdown 中创建模板
- laravel - 如何修复“PHP Parse 错误:语法错误,第 156 行 /var/www/.../vendor/laravel/RoutesRequests.php 中的意外 '='”
- java - 我可以修改和重置 java 方法参数吗
- html - 纯 HTML 后退按钮
- laravel - 图像不显示
- eclipse-rcp - 使用 tycho-p2-extras 镜像 Eclipse p2 存储库时如何获取源包