我正在使用Jquery的删除对话框。问题是我无法在提示或对话框中显示该项目。例如,对话框将提示如下:“您确定要删除此产品项吗?”。必须在对话框中显示“Product”一词,以便告知用户要删除的内容。
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>
答案 0 :(得分: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'));