1

你能帮我并告诉我如何将href发送到该代码中的数据:

$(".ad-gallery").on("click", ".ad-image", function () {
    $.fancybox({

        href: $(this).find("img").attr("src"), //here is the value i want to send
        titlePosition: 'outside',
        title: $(this).text(),
        'beforeShow': function () {
            var content = $('.fancybox-inner');  // for v2.x use : var content = $('.fancybox-inner');
            $('.fancybox-wrap').append('<div class="fancy_print"></div>'); // for v2.x use : $('.fancybox-wrap').append(...
            $('.fancy_print').bind("click", function () {

                var retVal = confirm("Are you sure you want to order it?");
                if (retVal == true) {
                        $.ajax({
                            type: "POST",
                            url: "WebForm1.aspx/coucou",
                            data: "{}",//$titre.serialize(),// and i want to give the value inside that data

谢谢

4

1 回答 1

0

在外部函数内部创建一个变量。

$(".ad-gallery").on("click", ".ad-image", function () {
    var $this = $(this),
       href = $this.find("img").attr("src");
    $.fancybox({
        href: href, //accessible here
        titlePosition: 'outside',
        title: $this.text(),
        'beforeShow': function () {
            //You can use href here
            var content = $('.fancybox-inner');  // for v2.x use : var content = $('.fancybox-inner');
            $('.fancybox-wrap').append('<div class="fancy_print"></div>'); // for v2.x use : $('.fancybox-wrap').append(...
            $('.fancy_print').bind("click", function () {
                //And here

                var retVal = confirm("Are you sure you want to order it?");
                if (retVal == true) {
                        $.ajax({
                            type: "POST",
                            url: "WebForm1.aspx/coucou",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            data: '{"href":"'+ href +'"}'

范围和闭包

于 2012-11-22T20:55:27.897 回答