我有這些HTML代碼段:JQuery的前綴選擇問題
<li class="icon iconDelete"><a href="/projects/delete/{id}/" title="Delete this test case."></a></li>
<li class="icon iconActive1"><a href="/projects/disable/{id}/" title="Disable this test case."></a></li>
<li class="icon iconActive0"><a href="/projects/enable/{id}/" title="Enable this test case."></a></li>
和
<div class="overlay" id="overlay" style="display:none;"></div>
<ul class="overlayBox" id="overlayBox">
<li id="overlayTop"></li>
<li id="overlayContent">
<b id="overlayTitle">Title</b><br />
<p id="overlayText">
Here comes a very important message for your user.
Turn this window off by clicking the cross.
</p>
</li>
<li id="overlayBottom"></li>
</ul>
我有這一塊的jQuery:
$(document).ready(
$(function()
{
$('a[title|="Enable this "]').click(
function()
{
alert(1);
$('#overlayTitle').text('Are you sure you want to enable this item?');
$('#overlayText').text('This will take effect for all parent items this item is assigned to.');
$('#overlay').fadeIn('fast',function()
{
$('#overlayBox').animate({'top':'160px'},500);
});
}
),
$('a[title|="Disable this "]').click(
function()
{
alert(2);
$('#overlayTitle').text('Are you sure you want to disable this item?');
$('#overlayText').text('This will take effect for all parent items this item is assigned to.');
$('#overlay').fadeIn('fast',function()
{
$('#overlayBox').animate({'top':'160px'},500);
});
}
),
$('a[title|="Delete this "]').click(
function()
{
alert(3);
$('#overlayTitle').text('Are you sure you want to delete this item?');
$('#overlayText').text('This will take effect for all parent items this item is assigned to.');
$('#overlay').fadeIn('fast',function()
{
$('#overlayBox').animate({'top':'160px'},500);
});
}
);
}
)
);
當我點擊的一個帶有title屬性的鏈接,jQuery進入所有.click()函數(3個警報將彈出),而不僅僅是指定前綴選擇器的那個。
任何想法爲什麼以及如何解決這個問題?
謝謝!