AngularJS:ng-disabled是否删除了输入值?

时间:2021-12-17 04:36:52

The title says everything... I've been reading several posts on * as well as the documentation, but I haven't found a satisfactory explanation yet.

标题说明了一切......我一直在阅读*上的几篇文章以及文档,但我还没有找到令人满意的解释。

If ng-disabled is activated, is the input value inside the tag removed?

如果激活ng-disabled,标签内的输入值是否被删除?

Let me illustrate with an example.

让我举一个例子来说明。

<form method="POST" name="form" action="">
    <select ng-model="model[1]"  
            ng-options="i for i in fc.items[1]" 
            ng-disabled="true">
    </select>
    <select ng-model="model[2]" 
            ng-options="i for i in fc.items[2]" 
            ng-disabled="false">
    </select>
    <input type="submit" value="Next"/>
</form>

The input value is results[2]:number:1. (number:1 is the expected result).

输入值为结果[2]:数字:1。 (数字:1是预期结果)。

When I remove ng-disabled, the result is results[1]:number:1 results[2]:number:1.

当我删除ng-disabled时,结果为结果[1]:数字:1结果[2]:数字:1。

I'm about to conclude the ng-disabled affects the input value, but I'd like to know if anyone here knows how to get all the input values (if it's possible).

我即将得出结论ng-disabled会影响输入值,但我想知道这里是否有人知道如何获取所有输入值(如果可能的话)。

2 个解决方案

#1


3  

No.

没有。

Disabling an input just make it unusable and unclickable. The value still persist.

禁用输入只会使其无法使用且无法点击。价值仍然存在。

Your value is not send because disabled elements in a form will not be submitted.

您的值未发送,因为表单中的已禁用元素将不会被提交。


From W3C Input disabling:

从W3C输入禁用:

A disabled input element is unusable and un-clickable.

禁用的输入元素不可用且不可单击。

The disabled attribute can be set to keep a user from using the element until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the element usable.

可以设置disabled属性以防止用户使用该元素,直到满足某些其他条件(例如选择复选框等)。然后,JavaScript可以删除禁用的值,并使元素可用。

Tip: Disabled input elements in a form will not be submitted.

提示:不会提交表单中已禁用的输入元素。

#2


1  

No, It doesn't remove input value at all. It just make input inaccessible. ng-disabled directive just add/remove disabled attribute based on expression passed to it.

不,它根本不会删除输入值。它只是使输入无法访问。 ng-disabled指令只根据传递给它的表达式添加/删除disabled属性。

ng-disabled="expression"

Look at the ngDisabled API for more vision here. Internally it calls attr.$set(attrName, !!value), which decides wheather to add/remove attribute from DOM element behind the scene from this method(Source Code).

在这里查看ngDisabled API以获得更多愿景。在内部,它调用attr。$ set(attrName,!! value),它决定从此方法(场代码)的场景后面的DOM元素添加/删除属性。

#1


3  

No.

没有。

Disabling an input just make it unusable and unclickable. The value still persist.

禁用输入只会使其无法使用且无法点击。价值仍然存在。

Your value is not send because disabled elements in a form will not be submitted.

您的值未发送,因为表单中的已禁用元素将不会被提交。


From W3C Input disabling:

从W3C输入禁用:

A disabled input element is unusable and un-clickable.

禁用的输入元素不可用且不可单击。

The disabled attribute can be set to keep a user from using the element until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the element usable.

可以设置disabled属性以防止用户使用该元素,直到满足某些其他条件(例如选择复选框等)。然后,JavaScript可以删除禁用的值,并使元素可用。

Tip: Disabled input elements in a form will not be submitted.

提示:不会提交表单中已禁用的输入元素。

#2


1  

No, It doesn't remove input value at all. It just make input inaccessible. ng-disabled directive just add/remove disabled attribute based on expression passed to it.

不,它根本不会删除输入值。它只是使输入无法访问。 ng-disabled指令只根据传递给它的表达式添加/删除disabled属性。

ng-disabled="expression"

Look at the ngDisabled API for more vision here. Internally it calls attr.$set(attrName, !!value), which decides wheather to add/remove attribute from DOM element behind the scene from this method(Source Code).

在这里查看ngDisabled API以获得更多愿景。在内部,它调用attr。$ set(attrName,!! value),它决定从此方法(场代码)的场景后面的DOM元素添加/删除属性。