我对 JQuery 有一个奇怪的问题,我正在尝试使用一个文本字段,它使用 JQuery UI 的自动完成来显示建议,并将每个选定的文本值附加到一个 div。除了每个文本标签,还有一个删除链接,但我无法让它工作。
自动完成功能就像一个魅力:
$( "#games" ).autocomplete({
source: "<?php echo base_url('game/game/autocomplete'); ?>",
dataType: "json",
type: "POST",
minLength: 1, // how many character when typing to display auto complete
// handling the select
select: function( event, ui ) {
$('#showgames').append('<span id="'+ui.item.value+'">'+ui.item.value+'<a href=# class="removegame">Remove</span>');
$('#games').val('');
return false;
}
});
// removing game items
$('.removegame').click(function(){
// The following never happens
alert("hi");
});
<div id="showgames">
// anchor links are generated by jquery here, within individual spans.
// these are not working
</div>
<div id="testing">
// This works
<a class=removegame href=#>Test link</a></span>
</div>
自动完成字段:(游戏)
<td align="left"><label for="genres">Genre(s):</label></td>
showgames div 的每个跨度对应于从“游戏”文本字段中获得的每个值。在这里,单击带有删除游戏的链接没有任何作用。它实际上应该像上面那样进入函数,并显示一个警报,但它从未发生过。
相反,如果我使用类 removegame 在页面上创建一个锚标记项,它就可以工作。但是当它使用 jQuery 生成时,它不起作用。我被逼疯了。有人可以帮帮我吗?
非常感谢您提前!!