.setAttribute(“禁用”,false);将可编辑的属性更改为false [英] .setAttribute("disabled", false); changes editable attribute to false

查看:1727
本文介绍了.setAttribute(“禁用”,false);将可编辑的属性更改为false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要有与单选按钮相关的文本框。因此,每个单选按钮应该启用它的文本框,并禁用其他。但是,当我将文本框的禁用属性设置为true时,它也会更改可编辑属性。我尝试设置可编辑属性再次真正的,但它没有工作。

这是我试过的:

JS函数:
$ b $ pre $ function enable(id)
{
var eleman = document.getElementById(id);
eleman.setAttribute(disabled,false);
eleman.setAttribute(editable,true);



$ b $ p $ X b


pre> < radio id =pnolabel =123onclick =enable('ad')/>


解决方案

a disabled 元素是(自我解释)禁用,从而逻辑上不可编辑。所以:
$ b


设置disabled属性[...]也改变editable属性


是一个明确定义的行为。



真正的问题在这里似乎是您要设置禁用 false 通过 setAttribute()期待。如果设置了 disabled -attribute,则该元素将被禁用,与其值无关(因此, disabled =true disabled =disabled disabled =false全部做同样的事情:元素被禁用)。您应该删除完整的属性:

  element.removeAttribute(disabled); 

或者直接设置该属性:

  element.disabled = false; 


I want to have textboxes related to radiobuttons. Therefore each radio button should enable it's textbox and disable the others. However when I set the disabled attribute of textbox to true, it changes the editable attribute too. I tried setting editable attribute true again but it did not work.

This was what I tried:

JS function:

function enable(id)
{
    var eleman = document.getElementById(id);
    eleman.setAttribute("disabled", false);
    eleman.setAttribute("editable", true);
}

XUL elements:

<radio id="pno" label="123" onclick="enable('ad')" />
<textbox id="ad" editable="true"  disabled="true" flex="1" emptytext="asd" onkeypress="asd(event)" tooltiptext="" >

解决方案

a disabled element is, (self-explaining) disabled and thereby logically not editable. so:

set the disabled attribute [...] changes the editable attribute too

is intended an well-defined behaviour.

the real problem here seems to be you're trying to set disabled to false via setAttribute() wich doesn't do what you're expecting. an element is disabled if the disabled-attribute is set, independent of it's value (so, disabled="true", disabled="disabled" and disabled="false" all do the same: the element gets disabled). you should instead remove the complete attribute:

element.removeAttribute("disabled");

or set that property directly:

element.disabled = false;

这篇关于.setAttribute(“禁用”,false);将可编辑的属性更改为false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆