什么是javascript中的.value变量的替代品?

时间:2021-10-02 18:24:09

I'm writing a page where I need to get the value attribute for the selected option within a select tag.

我正在编写一个页面,我需要在select标签中获取所选选项的value属性。

The way I usually do it like this: onchange="changeCurrentWebsite(this.options[this.selectedIndex].value)

我通常这样做的方式如下:onchange =“changeCurrentWebsite(this.options [this.selectedIndex] .value)

However every time I use ".value" in Javascript my IDE(Intellij) complains that that symbol is deprecated... Does anybody know the correct way to do it?

但是,每当我在Javascript中使用“.value”时,我的IDE(Intellij)就会抱怨该符号已被弃用...有人知道正确的方法吗?

2 个解决方案

#1


Instead of

this.options[this.selectedIndex].value

is it not possible to just use the "value" property of the element ? Like this :

是不是只能使用元素的“value”属性?像这样 :

document.getElementById('ID_OF_SELECT').value

Or, in your case :

或者,在您的情况下:

changeCurrentWebsite(this.value)

Does you IDE say it's deprecated too ?

你的IDE说它也被弃用吗?

#2


Intellij is incorrect. 'Value' is perfectly valid.

Intellij不正确。 '价值'是完全有效的。

Check W3C Documentation:

检查W3C文档:

http://www.w3.org/TR/html401/interact/forms.html#h-17.6

#1


Instead of

this.options[this.selectedIndex].value

is it not possible to just use the "value" property of the element ? Like this :

是不是只能使用元素的“value”属性?像这样 :

document.getElementById('ID_OF_SELECT').value

Or, in your case :

或者,在您的情况下:

changeCurrentWebsite(this.value)

Does you IDE say it's deprecated too ?

你的IDE说它也被弃用吗?

#2


Intellij is incorrect. 'Value' is perfectly valid.

Intellij不正确。 '价值'是完全有效的。

Check W3C Documentation:

检查W3C文档:

http://www.w3.org/TR/html401/interact/forms.html#h-17.6

相关文章