用`textarea.value(“")'设置值会引发“`TypeError`:`textarea.value`不是函数" [英] Setting value with `textarea.value("")` throws “`TypeError`: `textarea.value` is not a function”

查看:31
本文介绍了用`textarea.value(“")'设置值会引发“`TypeError`:`textarea.value`不是函数"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将< textarea> ( planned_use_select.nextSibling )的 value 设置为空字符串.

I’m trying to set the value of the <textarea> (planned_use_select.nextSibling) to an empty string.

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>

第一行工作正常(正确地应用了该类并隐藏了textarea),但第二行失败:它会产生此错误:

The first line works fine (correctly applies the class and hides the textarea) but the second line fails: it produces this error:

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

为什么我可以使用 .setAttribute()但不能使用 .value()?

Why can I use .setAttribute() but not .value()?

推荐答案

使用 planned_use_select.nextSibling.value ="

value 是可以获取或设置的属性.这不是功能.

value is a property which you can get or set. It is not a function.

这篇关于用`textarea.value(“")'设置值会引发“`TypeError`:`textarea.value`不是函数"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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