我正在尝试进行ajax点击以加载div功能。但点击功能不起作用。我在这里做错了什么?在这方面,任何人都可以帮助我吗?
来自Jsfiddle的var response = '<div class="icon_b">
<div class="clickficon"></div>
<div class="emicon-menu MaterialTabs">
<ul>
<li class="tab active"><a href="#starks-panel1"> Starks</a></li>
<li class="tab"> <a href="#lannisters-panel1"> Lannisters</a></li>
<li class="tab"> <a href="#targaryens-panel1"> Targaryens</a><span></span></li>
</ul>
<div class="panels">
<div id="starks-panel1" class="panel pactive"> a </div>
<div id="lannisters-panel1" class="panel"> b </div>
<div id="targaryens-panel1" class="panel"> c </div>
</div>
</div>
</div>';
$(document).ready(function () {
function showProfileTooltip(e, id) {
//send id & get info from get_profile.php
$.ajax({
url: '/echo/html/',
data: {
html: response,
delay: 0
},
method: 'post',
success: function (returnHtml) {
e.find('.user-container').html(returnHtml).promise().done(function () {
$('.emoticon').addClass('loaded');
});
}
});
}
function hideProfileTooltip() {
$('.the-container').removeClass('loaded');
}
$('body').on('change', '.emoticon', function(e) {
var id = $(this).find('.emoticon_click').attr('data-id');
showProfileTooltip($(this), id);
}, function () {
hideProfileTooltip();
});
});
答案 0 :(得分:2)
回调函数在那里无效,
//on load,click is more prefer than change
$('body').on('click', '.emoticon', function(e) {
var id = $(this).find('.emoticon_click').attr('data-id');
showProfileTooltip($(this), id);
});
//don't call like this
//, function () {
// hideProfileTooltip();
// });