我是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();但是得到上面提到的错误。
发布于 2016-03-09 04:46:07
而不是
var firstNameTextValue = $("#sec-" + n +" input").attr("id").$("#firstName").val();使用
var firstNameTextValue = $("#sec-" + n +" textarea[id='firstName']").val()如果n的值应该是1或2,这样它就会选择适当的section,并且您还需要在section旁边查找textarea而不是input,因为您没有使用input type='text',所以您使用了textarea作为用户输入。
https://stackoverflow.com/questions/35883008
复制相似问题