0

以下のコードの時点で、リンクをクリックしたときに AJAX 応答の後にファンシー ボックスが読み込まれません。

タグの ID は<a>動的に生成されます。

しかし、2回目に同じリンクをクリックするとロードされますが、AJAX関数も呼び出されます。

$(document).ready(function()
{

   $(".cont").live('click',function(e)
    {
        //Cancel the default action (navigation) of the click.
        e.preventDefault();

        var contentId = $(this).attr('id');


        $('#apps').load('/app/get-app-details', function(){
            $("#"+contentId).fancybox();
        });

    });


  });

<a class="cont" href="#device_detection" id="apps_<?= $regUsers->id; ?>"> Click to view apps</a>

解決策を教えてください。

4

1 に答える 1

0

これは機能しています。他の誰かが役に立つかもしれません

  $(".cont").live("click",function() {

      link=($(this).attr('href'));



            $.fancybox({
            'width'                : '1000',
            'href'                 : link,
            'height'            : '750',
            'autoScale'         : false,
            'transitionIn'        : 'none',
            'transitionOut'        : 'none',
            'type'                : 'iframe'
            }); 





      return false; // don't follow the link!
           });

Live は最新の jquery で非推奨になっているため、使用できます

$("body").on("click",".cont",function() {

      link=($(this).attr('href'));



            $.fancybox({
            'width'                : '1000',
            'href'                 : link,
            'height'            : '750',
            'autoScale'         : false,
            'transitionIn'        : 'none',
            'transitionOut'        : 'none',
            'type'                : 'iframe'
            }); 





      event.preventDefault(); // don't follow the link!
           });
于 2014-04-21T10:19:57.250 に答える