Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过div jquery中的类重申_Javascript_Jquery_Iteration - Fatal编程技术网

Javascript 通过div jquery中的类重申

Javascript 通过div jquery中的类重申,javascript,jquery,iteration,Javascript,Jquery,Iteration,假设我有以下结构: <div id="table"> <div class="row"> <div class="cell">a</div> <div class="cell">b</div> </div> <div class="row"> <div class="cell">d</div> <div class=

假设我有以下结构:

<div id="table">
  <div class="row">  
     <div class="cell">a</div>
     <div class="cell">b</div>
  </div>
  <div class="row">
     <div class="cell">d</div>
     <div class="cell">c</div>
  </div>
</div>

A.
B
D
C
我如何通过它们重申,我创建了相同的结构,但使用了
而不是
而不是
,使用div的内容而不是

我试着做一些类似的事情

 let topics_table = '<table>'
                $('#table > .row').each(function(){
                    topics_table += '<tr>'
                        $(this + ' .cell').each(function(that){
                            topics_table += '<td>' + that.text() + '</td>'    
                        })
                    topics_table += '</tr>';
                })
 topics_table += '</table>`
let topics_table=''
$('#table>.row')。每个(函数(){
主题\u表+=“”
$(this+'.cell')。每个(函数(that){
主题\u table+=''+that.text()+''
})
主题_表+='';
})
主题\u表+='`
但我有个错误

$(this + ' .cell')
应该是

$(this).find('.cell')
// or
$('.cell', this)
您正在尝试将字符串连接到DOM元素

.each(function(that){
   topics_table += '<td>' + that.text() + '</td>'    
})
。每个(函数){
主题\u table+=''+that.text()+''
})
^^这也是一个问题,因为jQuery将索引作为第一个参数而不是元素传入

.each(function(index, that){
   topics_table += '<td>' + that.innerText + '</td>'    
})
.each(函数(索引,即){
主题\u table+=''+that.innerText+''
})