简体   繁体   English

使用 `textarea.value("")` 设置值会抛出“`TypeError`: `textarea.value` 不是函数”

[英]Setting value with `textarea.value("")` throws “`TypeError`: `textarea.value` is not a function”

I'm trying to set the value of the <textarea> ( planned_use_select.nextSibling ) to an empty string.我正在尝试将<textarea> ( planned_use_select.nextSibling ) 的value设置为空字符串。

 var planned_use_select = document.querySelector("select[name=planned_use]"); planned_use_select.addEventListener("change", function() { planned_use_select.nextSibling.setAttribute("class", "hidden"); planned_use_select.nextSibling.value(""); });
 <div class="form-input"> <select name="planned_use"> <option value="Foo">foo</option> <option value="Bar">bar</option> <option value="Other">Something else</option> </select> <textarea class="other_planned_use" name="other_planned_use" placeholder="We'd love to know more!"></textarea> </div>

The first line works fine (correctly applies the class and hides the textarea) but the second line fails: it produces this error:第一行工作正常(正确应用类并隐藏 textarea)但第二行失败:它产生此错误:

index.js:200 Uncaught TypeError: planned_use_select.nextSibling.value 
is not a function
at HTMLSelectElement.<anonymous> (index.js:200)

Why can I use .setAttribute() but not .value() ?为什么我可以使用.setAttribute()而不是.value()

Use planned_use_select.nextSibling.value = ""使用planned_use_select.nextSibling.value = ""

value is a property which you can get or set. value是您可以获取或设置的属性。 It is not a function.它不是一个函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM