2016-11-26 48 views
0

我想實現像

1)我有一個盒子,裝有1項與刪除圖標

2)單擊刪除圖標我AP表現的確認框建立與自舉模式

3)從盒

點擊「是」,我刪除項目現在的問題是像我如何可以通過先刪除圖標的$(本)???

代碼刪除就像

<a class="removepromo pull-left" data-code-name="test" data-rel="21468" href="javascript:void()"> 
<i class="fa fa-remove remove-btn" title="Remove Promo"></i> 
</a> 

現在對是從模型中點擊我要刪除按鈕的所有屬性

這裏click事件兩者的結合(刪除圖標,模型是按鈕)是不同的,所以如何通過$(this)對象?

目前的解決方案

我可以張貼的答案,因爲這是對實現它的最醜陋的方式之一,這就是我想

$('body').on('click','.apply_promo_code',function(e){ 
e.preventDefault(); 
var url = $(this).data('href'); 
// open model code, where I have taken yes and no button 
//Code for yes button is like : 
var btn ='<div data-ref="'+url+'" class="btn confirm-btn confirm-left-btn removepromo_yes">Yes</div>'; 
return false; 
} 

$('body').on('click','.removepromo_yes',function(e){ 
e.preventDefault(); 
var url = $(this).data('ref'); 
// all other stuff 
} 

enter image description here

enter image description here

+0

您是否嘗試過使用jQuery來做這件事?如果是這樣,你能告訴我們的代碼 –

+0

莫代爾如何被調用?它是某種你用來顯示模態的插件嗎? – Sreekanth

+0

讓我分享該代碼以及 –

回答

0

將$(this)保存在一個變量中並使用循環ķ功能的另一種方法是這樣的:

$('.apply_promo_code').on('click',function(e){ 
e.preventDefault(); 
    var removeObject=$(this);  
$('.removepromo_yes').on('click',function(e){ 
    e.preventDefault(); 

    var url =removeObject.data('href')  
}) 
return false; 
}) 

是沒有問題的,如果你確定你是按鈕的onClick handlere在以前的功能

+0

你在這裏做了什麼我沒有得到它 –

+0

我將更新我的答案 – farhadamjady

0

您可以添加功能,並通過這個作爲一個參數

<a class="removepromo pull-left" data-code-name="test" data-rel="21468" href="javascript:void()" onclick="onremove(this)"> 
<i class="fa fa-remove remove-btn" title="Remove Promo"></i> 
</a> 



    function onremove(val){ 
      console.log(val) 
     // val will give you current anchor tag so you can do whatever you want to do 
    } 
+0

你沒有得到我的問題,點擊下一步按鈕我想要第一個lnk –

+0

在你上面的排隊你還沒有提到下一個鏈接你說你點擊刪除圖標模態打開並確認後你想刪除屬性的權利? –

+0

是的,你是對的 –