在this小提琴中,单击图像时会显示jQuery对话框。该对话框应包含特定于图像的文本,例如,关于律师事务所图像的律师事务所的文本,关于行业形象的行业文本等。
问题在于,一旦您点击了三个图像中的每一个,任何进一步点击任何图像都会返回与您单击的三个图像中的最后一个图像相关的对话框,而不是您刚才的图像对话框点击。
有人可以指出我错了吗?
HTML
<div id="sf">
<a href="dialogcontent/lawfirms.html" title="Law firms" id="sfimage">
<div class="circle hovershadow lawfirms lawfirms-box-shadow">Law firms</div>
</a>
<a href="dialogcontent/industry.html" title="Industry" id="sfimage">
<div class="circle hovershadow industry industry-box-shadow">Industry</div>
</a>
<a href="dialogcontent/in-house.html" title="In-house legal counsel" id="sfimage">
<div class="circle hovershadow in-house in-house-box-shadow text">In-house
legal counsel</div>
</a>
</div>
使用Javascript:
$(document).ready(function () {
var $loading = $('<img src="http://ubuntuone.com/5qQ3i4ctM8HAvRsSIZKgqd" alt="Loading ..." class="loading">');
var $dialog = $('<div></div>')
$('#sf a').each(function () {
$dialog.append($loading.clone());
var $link = $(this).one('click', function () {
$dialog.load($link.attr('href') + ' #content')
.dialog({
title: $link.attr('title'),
width: 500,
height: 300
});
$link.click(function (e) {
// e.preventDefault();
$dialog.dialog('open');
return false;
});
return false;
});
});
});
答案 0 :(得分:0)
您正在使用'one'方法。因此,每个元素最多只执行一次click事件。
如果该元素的处理程序已经执行,那么将显示对话框中最后加载的内容。