【发布时间】:2015-06-30 21:40:35
【问题描述】:
我想要的是,当单击按钮内的 (X) 时,它应该触发注册的相应回调。但我不知道为什么它失败了。以下是我尝试过的:
HTML
<div id="cover"></div>
<template id='filtertemp'>
<button id="filtype" class='filbut' data-filter=""></button>
</template>
<button id='create' onclick="filter();">Click</button>
JQUERY
function filter(){
var content= $('#filtertemp')[0].content;
if(content){
var filType= content.querySelector('#filtype');
$(filType).text("type : sometype");
var clone= document.importNode(content,true);
$('#cover').append($(clone));
$('#cover > .filbut:last-child').append('<span class="glyphicon glyphicon glyphicon-remove"></span>');
}
$('.glyphicon').on('click', function(){
alert('Remove');
});
}
这里是小提琴链接:http://jsfiddle.net/wtce6dje/
我什至尝试在下面注册监听器,但这似乎也起作用了:
$('body').on('click','.glyphicon', function(){
alert('Remove');
});
【问题讨论】:
-
在共享小提琴中工作正常。
-
你需要这种东西吗jsfiddle.net/wtce6dje/1
-
但 id 应该是唯一的
-
@MilindAnantwar 对我不起作用..我正在使用 mozilla 浏览器
-
@gmo 如果它不适用于 mozilla,有什么解决方法?
标签: jquery html twitter-bootstrap