[問題] 呼叫div,hide該div後,重複執行的bug?
[問題描述]
當點擊<a>時,會呼叫<div id="shareit-box">顯示在頁面上,
當點擊<div id="shareit-box">裡的按鈕,進行關閉動作時,
我放置了 alert("結束"+boxtitle); ,看關閉按鈕執行時,跳了幾次alert…
測試結果時,會一直不斷跳出alert,而且跳出alert的順序,
會是我每次點過<a>的連結順序…
我想問的是…是否有方法,可以第一次點擊顯示alert之後,
該物件執行就結束了,其他的alert不再會執行?
謝謝!
[html]
<div style="border:#000000 1px solid; margin-left:200px;">
<a href="#" class="alert" rel="shareit" boxtitle="AAA">AAA</a><br/>
<a href="#" class="alert" rel="shareit" boxtitle="BBB">BBB</a><br/>
<a href="#" class="alert" rel="shareit" boxtitle="CCC">CCC</a><br/>
<a href="#" class="alert" rel="shareit" boxtitle="DDD">DDD</a><br/>
<a href="#" class="alert" rel="shareit" boxtitle="EEE">EEE</a><br/>
<a href="#" class="alert" rel="shareit" boxtitle="FFF">FFF</a><br/>
<a href="#" class="alert" rel="shareit" boxtitle="GGG">GGG</a><br/>
</div>
<div id="shareit-box" style="display:none;">
<div id="shareit-header"></div>
<div id="shareit-body">
<div id="shareit-submitbox">
<input name="btn_end" type="button" class="style2" />
</div>
</div>
</div>
[jquery]
$(document).ready(function()
{
$('a[rel=shareit]').mousedown(function()
{
var height = $(this).height();
var top = $(this).offset().top;
//get the left and find the center value
var left = $(this).offset().left +
($(this).width() /2) -
($('#shareit-box').width() / 2);
$('#shareit-header').height(height);
$('#shareit-box').show();
$('#shareit-box').css({'top':top, 'left':left});
var box_title = $(this).attr("boxtitle");
$("input[name=btn_end]").click(function()
{
alert("結束!"+box_title); // <=測試用的alert
$('#shareit-box').hide();
return false;
});
$('#shareit-header').click(function () {
$('#shareit-box').hide();
})
});
});
以上,謝謝。
--
自戀:26.42% 狗血:21.25% 愛:17.54%
超合金:11.85% 心中的翡翠森林:8.57% 燃燒的小宇宙:6.99%
渣渣:6.86% 反動思想:0.53%
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 211.75.186.7
→
07/27 23:57, , 1F
07/27 23:57, 1F
→
07/27 23:57, , 2F
07/27 23:57, 2F
→
07/27 23:59, , 3F
07/27 23:59, 3F
→
08/05 00:23, , 4F
08/05 00:23, 4F
→
08/05 00:23, , 5F
08/05 00:23, 5F
→
08/05 00:24, , 6F
08/05 00:24, 6F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 3 篇):