2012-05-01 140 views
0

我在彈出窗口中顯示用戶單擊的最後一個元素而不是當前元素時出現問題。我有幾個不同的優惠券,用戶可以點擊打印。例如,如果用戶點擊具有「測試」標識的優惠券,則什麼都不會發生,但是當用戶第二次點擊時,優惠券出現。在這種情況下,無論點擊哪張優惠券,「測試優惠券」都會繼續出現。如果手動刷新頁面,則用戶可以點擊新的優惠券。我究竟做錯了什麼?帶彈出窗口的jquery問題

$(".coupon").click(function() { 
    var id = $(this).attr("id"); 
    $('.pop').popupWindow({ 
     windowURL:'coupons/' + id + '.html' 
    }); 
}); 

.coupon { 
margin:10px; 
height:152px; 
width:193px; 
position:relative; 
cursor:pointer; 
float:left; 
} 

.coupon .price { 
margin-top:7px; 
font-size:29px; 
font-weight:bold; 
color:white; 
text-align:center; 
} 

.coupon .title { 
margin-top:5px; 
font-size:18px; 
font-weight:bold; 
color:black; 
text-align:center; 
font-family:'Times New Roman',Georgia,Serif; 
} 

<div class="coupon pop" id="test1"> 
    <div class="price"> 
    $5.00 OFF 
    </div> 
    <div class="title"> 
    Test 
    </div> 
</div> 

<div class="coupon pop" id="test2"> 
    <div class="price"> 
    $5.00 OFF 
    </div> 
    <div class="title"> 
    Another test 
    </div> 
</div> 
+0

什麼popupWindow功能做什麼?你使用任何插件? – Shyju

+0

似乎基本上沒問題。你可以發佈你的其他代碼或jsFiddle嗎? – j08691

+0

@Shyju,我使用這裏的插件:http://www.swip.codylindley.com/popupWindowDemo.html – Muzz

回答

0

我試試這個代碼和工作

的javascript:

<script type="text/javascript"> 
$(function() { 
$('.coupon').each(function(){ 
    $(this).popupWindow({ 
     windowURL:$(this).attr("href") 
    }); 
}); 
}); 
</script> 

的html代碼:

<a class="coupon" href="http://google.com" onclick="return false;" id="google">Google</a> 
<a class="coupon" href="http://yahoo.com" onclick="return false;" id="yahoo">Yahoo</a> 

合Ë在屬性的變化不會傷了你的項目

CHEARS

更新: 我你的div標籤轉換成

<a class="coupon" id="test1" href="_your_link_"> 
    <span class="price">$5.00 OFF</span> 
    <span class="title">Test </span> 
</a> 
+0

感謝您的回答。我已經嘗試了這一點,但它糾正了不得不點擊兩次來調出新窗口,現在我只能得到HTML中列出的第一個總共5個優惠券。我無法獲得任何其他優惠券。 – Muzz

+0

你可以使用班級優惠券發佈鏈接的HTML代碼嗎? – DFuchidzhiev

+0

好的,我現在把它貼出來。謝謝你看看。 – Muzz