不能在元素textarea上使用find,它是td的子元素

Cant use find on element textarea which is child of td

本文关键字:元素 它是 td find textarea 不能      更新时间:2023-09-26

我在targetTD[6].find('textarea').text()上得到一个错误,说targetTD[6]。Find不是一个函数。在'targetTD[6].find('textarea')'中,'targetTD[6]. '

        $(document).ready(function () {
            $(document.body).on('click','.edit',function () {// use button class ince ID has to be unique per button
                    var targetTD;              
                    if( $(this).find('i').hasClass('glyphicon-edit'))
                    {         
                        targetTD = $(this).parents('tr').find('td');  // gives all TDs of current row
                        if (targetTD[6].firstChild.children.length)   // the value cell is what we want
                        {
//                            targetTD[6].firstChild.children.item().setAttribute('readonly','false');                            
                              alert(targetTD[6].find('textarea').text());
                        }

我试图在<td><div> <textarea readonly> some text </textarea><div><td>中找到一个文本区域。如何移除readonly属性?为什么我不能使用find ?

尝试替换:

targetTD[6].find('textarea').text();

:

$(targetTD[6]).find('textarea').text();

因为targetTD是一个没有包装元素的数组。此外,要删除readonly属性,请使用:

$(targetTD[6]).attr("readonly", false);

targetTD[6]是原生JavaScript节点。你需要将它包装在jQuery选择器$()

像这样:$(targetTD[6]).find