-2

我正在尝试创建类似于定义为对话框的内容,该对话框会在单击按钮时出现,并且应该显示标题、随机图像和按钮以进一步处理原始请求。

function custom_display_reminder(theHTML,theDownloadLink){if(typeof jQuery.ui!='undefined'){$("#dialog").attr("title","Please help spread the word").html(theHTML);$("#dialog").dialog({modal:true,width:375,buttons:{"Continue to Download":function(){$(this).dialog("close");window.location=theDownloadLink;}}});}else{window.location=theDownloadLink;}}
function custom_reminder(aelem,topic){theLink=$(aelem).attr("href");
    $.ajax({
        type:"POST",
        url:"/db/ajax.php",
        data:"action=reminder&thepath="+theLink+"&topic="+topic,
        dataType:"json",
        error:function(){window.location=theLink;},
        success:function(msg){if(msg.status==1)custom_display_reminder(msg.html,theLink);
        else{custom_message(msg.message,"error");}}});}

我在其中一个网站上找到了上面的脚本,该网站具有我正在尝试实现的特定功能,但无法理解该过程。有人可以帮我解释该脚本的过程和所有调用吗?

提前致谢

4

1 回答 1

1

在您发布的代码中,theHTML 和 theDownloadLink 是从您在其下方发布的函数中的第一个函数(可能还有脚本中的其他任何位置)提供给第一个函数的参数。在这种情况下,它指的是 msg.html 的 HTML 和 theLink,它是所选特定 a 标记的 href 值(一个 URL)。

$.ajax 只是指一个异步 HTTP(或 AJAX)请求,有关它的文档可以在这里找到:jQuery.ajax()

可以在此处找到有关 jQuery 的更多文档以帮助您完成此操作:jQuery API 文档。阅读和理解本文档将更好地帮助您理解上面的代码,并使编写自己的实现更容易。如果您是 JavaScript 新手,我强烈建议您在线搜索教程,或查看 W3Schools 文档。

于 2013-02-27T11:04:39.670 回答