:disabled为false不生效
时间: 2023-09-01 21:07:25 浏览: 182
如果使用HTML的disabled属性将一个表单控件禁用,它将被禁用并且不能与用户交互。如果你想启用该控件,应该将disabled属性设置为true。如果你将disabled属性设置为false,它不会生效,因为disabled属性只有true和false两种值。如果你想重新启用该控件,应该从DOM中删除disabled属性。例如,可以使用以下代码启用具有id="myInput"的输入框:
```
document.getElementById("myInput").removeAttribute("disabled");
```
相关问题
el-tree disabled: true不生效
如果你使用的是 Element UI 的 el-tree 组件,并且设置了 `disabled: true` 但是没有生效,可能是因为你没有同时设置 `node-key` 属性。
在 el-tree 组件中,如果你想禁用某个节点,需要设置该节点的 `disabled` 属性为 `true`,同时需要设置 `node-key` 属性来指定节点的唯一标识符。例如:
```html
<el-tree
:data="treeData"
:node-key="node => node.id"
:props="treeProps"
:expand-on-click-node="false"
:default-expand-all="true"
show-checkbox
default-expand-all
check-strictly
:disabled="isTreeDisabled"
@check-change="handleCheckChange"
/>
```
其中,`:node-key="node => node.id"` 表示节点的唯一标识符为 `id` 属性。如果你的节点没有 `id` 属性,需要根据实际情况修改。`:disabled="isTreeDisabled"` 表示树组件的禁用状态由 `isTreeDisabled` 变量控制。
如果你已经正确设置了 `node-key` 属性,但是禁用状态依然没有生效,可能是因为你的数据源中的节点没有设置 `disabled` 属性。你可以在数据源中为需要禁用的节点添加 `disabled: true` 属性,例如:
```js
{
id: 1,
label: '一级 1',
disabled: true, // 禁用状态
children: [
{
id: 4,
label: '二级 1-1',
children: [
{
id: 9,
label: '三级 1-1-1'
}
]
}
]
}
```
如果你仍然遇到问题,可以提供更多的代码和具体的错误信息,方便我帮助你解决问题。
上一段代码中 th:if 都不符合条件 为什么 th:disabled="${true}" 会生效?
在你提供的代码中,`th:disabled`属性被设置为`${true}`,这意味着它的值将始终为`true`,无论`th:if`表达式的条件是否成立。因此,即使`th:if`表达式的条件不成立,`th:disabled`属性仍然会被设置为`true`,因此文本框将被禁用。
需要注意的是,如果你将`th:disabled`属性设置为`${false}`,或者不设置`th:disabled`属性,那么即使`th:if`表达式的条件不成立,文本框仍然会启用。这是因为HTML规范中规定,如果`disabled`属性的值为`false`或为空,那么元素将启用。
因此,如果你想确保`th:disabled`属性的值取决于`th:if`表达式的条件,你可以使用以下代码:
```
<textarea name="drawDescribed" id="drawDescribed"
th:text="${spotCheck.drawDescribed}"
class="form-control" style="resize: none;"
rows="5" maxlength="512" placeholder="必填,最大限制512字符"
th:if="${currentProcess == null or currentProcess.userId != userId or currentProcess.currentNode != 106}"
th:disabled="${currentProcess != null and currentProcess.userId == userId and currentProcess.currentNode == 106}">
</textarea>
```
在这个修正后的代码中,`th:disabled`属性的值取决于`th:if`表达式的条件。如果`th:if`表达式的条件不成立,`th:disabled`属性的值将为`false`,文本框将启用。如果`th:if`表达式的条件成立,`th:disabled`属性的值将取决于`currentProcess`对象的属性值。
阅读全文
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)