-1

我有以下代码

<li id="btemaildelete"><a href="##" onClick="return confirm('Are you sure you want to delete this Email Address?');"><i class="cus-cancel"></i> Delete</a></li>

并想拨打以下电话

emaildelete.cfm?intuserid=1

你能帮我理解一下吗?

4

4 回答 4

1

如果您包含 jQuery:

$.get("emaildelete.cfm", {intuserid: 1}, function(data) {
    // data contains the response of emaildelete.cfm
});

要在 jQuery 中捕获单击事件,您可以执行以下操作:

HTML:
<a href="..." data-id="1">Delete</a>

JavaScript:
$(document).ready(function() {
    $("a[data-id]").click(function() {
       var confirm = confirm("Are you sure u wanna delete?");
       if(!confirm) return false;

       var deleteId = $(this).data("id");
       $.get("emaildelete.cfm", {intuserid: deleteId}, function(data) {
           // data contains the response of emaildelete.cfm
       });

       return false;
    });
});   

使用该代码,您不再需要“onclick”属性。

于 2013-04-02T11:11:12.277 回答
0

您必须从链接本身传递 id,不确定如何诚实地通过 aspx 填充这些链接。您只需要将电子邮件的 id 放入链接的 id 中,但是您的应用程序可以这样做。

<li class="btemaildelete"><a href="##" class="deleteLink" id="get your ID in here" 
onClick="return confirm('Are you sure you want to delete this Email Address?');"><i 
class="cus-cancel"></i> Delete</a></li>

$(".deleteLink").on("click",function(){
$.ajax({
    type: 'POST',
    url: 'emaildelete.cfm',
    data: '{ intuserid : $(this).attr("id") }',
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    success: function(msg) {
        alert('Email deleted');
    }
});
});
于 2013-04-02T11:17:21.013 回答
0

这是一个例子

$.ajax({
    type: 'POST',
    url: 'url',
    data: '{ }',
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    success: function(msg) {
        // Do something interesting here.
    }
});
于 2013-04-02T11:09:50.847 回答
0

试试这样:

<li id="btemaildelete"><a href="##" onClick="call_function();"><i class="cus-cancel"></i> Delete</a></li>

在您的 JavaScript 代码中:

function call_function() {
    if(confirm('Are you sure you want to delete this Email Address?'))
     {
     $.ajax({
     url: "emaildelete.cfm?intuserid=1",  //Or any other server page you want
     type: "POST",
     success: function (response) {
      alert('Success' + response);
     }
    });
于 2013-04-02T11:14:19.627 回答