我有以下代码:
@Configuration
@EnableMetrics(proxyTargetClass = true)
@ComponentScan(basePackages = "com.inq")
public class SsvpApiMetricsConfig extends MetricsConfigurerAdapter {
@Resource
private MetricRegistry registry;
@PostConstruct()
public void init() {
configureReporters(registry);
}
@Override
public void configureReporters(MetricRegistry metricRegistry) {
registerReporter(JmxReporter.forRegistry(metricRegistry).
inDomain("com.inq.metrics").build()).start();
}
}
当该元素被动态添加时,我想将该元素作为目标。所以我用:
jQuery(function($){
$( '.comment-form' ).submit(function(){
// do stuff
});
});
但是,动态创建元素时永远不会添加事件触发器。是否存在以下问题:
jQuery(function($){
$(document).on('submit', '.comment-form',function(){
// do stuff
});
});
据我所知,这是正确的。
答案 0 :(得分:1)
尝试
jQuery(function($){
$(body).on('submit', '.comment-form',function(){
// do stuff
});
});
答案 1 :(得分:0)
选中此项并根据需要更新代码
$(".add_new").click(function(){
$(".form_area").html('<form class="main_form"><input type="submit" value="submit"></form>');
});
$(document).on('submit','.main_form',function(){
alert('Form submit');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div><button class="add_new"> Add New Form </button></div>
<div class="form_area">
<!--For dynamic added content-->
</div>