如何使用 Jquery 在对话框中显示要删除的项目

How to display the item to be deleted in the dialog using Jquery?

本文关键字:删除 项目 显示 何使用 Jquery 对话框      更新时间:2023-09-26

我正在使用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));
              }
            }); 

网页代码:

<td><a class="delete_link" href='del.php?&opr=delMedicine&id=<?php echo $test['id'];?>' title="Delete">
<div id="remove" ></div>
在我看来

,您需要使用变量$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'));