2017-11-10 116 views
0

我动态创建了一个div,加载了另一个html代码,并将其加载到一个静态元素中。Pont动态添加元素来加载另一个元素

var myDiv = document.createElement('div'); 
$(studentReports).attr('id', 'studentReports'); 
$(studentReports).load('reports_tables.html .studentReports'); 

$(reports).append(studentReports); 

//The element *reports* is in DOM, has an id="reports" 
//among his clases it has the class="reports" 

在这个poitnt,它的工作就好了,但是当我尝试点学生报告和追加甚至文本,这是行不通的

我试图使用的方法,我下面搜索在这里:

$('body').find('.studentReports').append(...); 
$('#reports').find('.studentReports').append(...); 
$('.studentReports', '.reports').append(...); 
$('div.reports div.studentReports').append(...); 
+0

请包括您的HTML结构,您应该向我们展示一个[mcve] –

回答

0

http://api.jquery.com/load/

负载需要,这将是一个可选的完整方法当负载完成时执行。为了确保页面中存在响应的内容,您需要将您的辅助逻辑作为此完整回调逻辑的一部分。像...

$(myDiv).load('hmlFile.html .dynamicElementClass', function(){ 
    $('body').find('.dynamicElementClass').append(...); 
});