2016-02-20 27 views
1

我正在使用Jquery的刪除對話框。問題是我無法在提示或對話框中顯示該項目。例如,對話框會提示如下:「您確定要刪除此產品項目嗎?」。必須在對話框中顯示「產品」一詞,以便用戶知道要刪除的內容。如何使用Jquery在對話框中顯示要刪除的項目?

jQuery代碼:

var del = function($element) { 
       $('#remove').dialog({ 
       title: 'Delete', 
       dialogClass: "clickoncloseoutside", 
       open: function() { 

       var prompt = 'Are you sure want to this'.$(this.href).' item?'; //it doesn't work 
       $('.delete_link').data(this.href); //it doesn't work 

       //It should display like this: Are you sure you want to delete this Product item? 

       $(this).html(prompt); 
       }, 
       buttons: { 
        "Delete item": function() { 
        $(this).dialog("close"); 
        $element.data('allow', true); // Allow the next click to proceed 
        $element[0].click(); // Hit the DOM native click event 
        }, 
        Cancel: function() { 
        $(this).dialog("close"); 
        } 
       } 
       }); 
      } 

      $('.delete_link').click(function(e) { 
       if (!$(this).data('allow')) { 
       e.preventDefault(); 
       del($(this)); 
       } 
      }); 

HTML代碼:

<td><a class="delete_link" href='del.php?&opr=delMedicine&id=<?php echo $test['id'];?>' title="Delete"> 

<div id="remove" ></div> 

回答

1

在我看來,你需要參考使用,你是作爲一個參數考慮在變量$element鏈接功能del()

例如,使用像你的例子href屬性:

//$element is the clicked link 
var prompt = 'Are you sure want to this' + $element.attr('href') + ' item?'; 
$('.delete_link').data($element.attr('href')); 
+0

注意,這會顯示該鏈接的'href'屬性,而不是鏈接文本,因爲我是玩掉的例子,你發佈。要獲得鏈接文本,你可以使用'$ element.html()'。 – shamsup

相關問題