简体   繁体   English

从表格HTML获取textarea值

[英]get textarea value from table HTML

I want to get the data in the textarea which is in nested table. 我想在嵌套表中的textarea中获取数据。 I use the row Index to get the data in that row. 我使用行索引来获取该行中的数据。

I tried this , but it is not work. 我试过了,但是没有用。

var note = document.getElementById($index).cells[3];
var y = document.getElementsByTagName("textarea").value;

Here is the table. 这是桌子。

<tr ng-repeat="(key, x) in records" id="{{$index}}">
    <td>{{key}}</td>
    <td>{{x.title}}</td>
    <td>{{x.year}}</textarea></td>
    <td>
         <textarea rows="2" cols="30">{{x.note}}</textarea>
         <button type="button" ng-click="update($index)">Update</button>
    </td>
    <td><button type="button" ng-click="delete($index)">Delete</button></td>
</tr>

Note that you also have the ending of a previous textarea control here, which might cause a problem for getElementsByTagName: 请注意,这里还具有上一个textarea控件的结尾,这可能会导致getElementsByTagName出现问题:

<td>{{x.year}}</textarea></td>

 var y = document.getElementsByTagName("textarea")[0].value; alert(y); 
 <tr> <td>17</td> <td>Title</td> <td>Year</td> <td> <textarea rows="2" cols="30">this is my note</textarea> <button type="button">Update</button> </td> <td><button type="button">Delete</button></td> </tr> 

Maybe here is the error, you are closing a textarea: 也许这是错误,您正在关闭文本区域:

<td>{{x.year}}</td>

After try with it: 尝试之后:

var y = document.getElementsByTagName("textarea")[0].value;

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

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