伙计们!我正在做一些前端工作,使用doT.js生成内容,使用jquery ui显示工具提示。
{{##def.defboardtooltip:
<div class='tooltip'>
<!-- some html code -->
<a id='bdetails' href='#'>Click for details</a></div>
</div>
#}}
以及如何使用:
<div class="participant" title="{{#def.defboardtooltip}}">
我正试图用jquery()将事件添加到一个元素中:
$(document).ready(function () {
// ...enter code here
$('#bdetails').click(function (e) {
// some code
console.log('fired');
});
});
而且我从来没见过"被炒鱿鱼"。我很困惑。
jQuery Event委托是您的朋友。
尝试:
$(function()
{
$(document).on('click', '#bdetails', function(e)
{
var a = $(this);
});
});
这将把事件过滤到你的#bdetails元素中,你也可以在这里使用任何有效的jQuery选择器;例如,"a"以委派所有锚标签点击。