gpt4 book ai didi

javascript - 错误未捕获类型错误 : Cannot read property '$' of undefined while getting value of input in section element

转载 作者:行者123 更新时间:2023-12-02 14:54:56 27 4
gpt4 key购买 nike

我是 JS 世界的新手,我陷入了错误

Uncaught TypeError: Cannot read property '$' of undefined

我有两个<section>元素说

<section id = "sec-1">                 
<textarea id="firstName" ></textarea>
</section>
<section id = "sec-2">
<textarea id="firstName"></textarea>
</section>

在下面的脚本中我想获取 <textarea> 的值作为

var firstNameTextValue = $("#sec-" + n +" input").attr("id").$("#firstName").val();

但出现上述错误。

最佳答案

而不是

var firstNameTextValue = $("#sec-" + n +" input").attr("id").$("#firstName").val();

使用

var firstNameTextValue = $("#sec-" + n +" textarea[id='firstName']").val()

其中n的值应该是1或2,以便它选择适当的部分,并且您还需要在侧面找到textarea而不是input section 因为您尚未使用 input type='text',所以您已使用 textarea 进行用户输入

关于javascript - 错误未捕获类型错误 : Cannot read property '$' of undefined while getting value of input in section element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35883008/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com