简体   繁体   中英

Jquery .load img not working in firefox and IE!

I have this javascript in my website and its works great to load image on click but not fork in Firefox or IE!

<script type="text/javascript">
                $(document).ready(function(){
                  $("#photo1").click(function(){
                    var img = new Image();
                    $(img).load(function () {
                        $('#big-image').hide();
                        $('#big-image').attr('src', '{/literal}{$purl}/t/{$p.p1}?{$smarty.now}{literal}');  
                        $('#big-image').fadeIn();
                    }).error(function() {
                    }).attr('src', '{/literal}{$purl}/t/{$p.p1}?{$smarty.now}{literal}');
                  });
                  {/literal}
                  {if $p.p2 ne ""}
                  {literal}
                  $("#photo2").click(function(){
                    var img = new Image();
                    $(img).load(function () {
                        $('#big-image').hide();
                        $('#big-image').attr('src', '{/literal}{$purl}/t/{$p.p2}?{$smarty.now}{literal}');  
                        $('#big-image').fadeIn();
                    }).error(function() {
                    }).attr('src', '{/literal}{$purl}/t/{$p.p2}?{$smarty.now}{literal}');
                  });
                  {/literal}
                  {/if}
                  {if $p.p2 ne ""}
                  {literal}
                  $("#photo3").click(function(){
                    var img = new Image();
                    $(img).load(function () {
                        $('#big-image').hide();
                        $('#big-image').attr('src', '{/literal}{$purl}/t/{$p.p3}?{$smarty.now}{literal}');  
                        $('#big-image').fadeIn();
                    }).error(function() {
                    }).attr('src', '{/literal}{$purl}/t/{$p.p3}?{$smarty.now}{literal}');
                  });
                  {/literal}
                  {/if}
                  {literal}
                });
                $(document).ready( function() {
                 $('.gig-desc').linkify();
                    $(".gig-desc a").each(function() {
                        $(this).attr("target", "_blank");
                    });
                });
                </script>

And here is image div tag:

<div id="photo1"><img alt="{$p.gtitle|stripslashes}" src="{$purl}/t2/{$p.p1}?{$smarty.now}" /></div>    
{if $p.p2 ne ""}<div id="photo2"><img alt="{$p.gtitle|stripslashes}" src="{$purl}/t2/{$p.p2}?{$smarty.now}" /></div>{/if}
{if $p.p3 ne ""}<div id="photo3"><img alt="{$p.gtitle|stripslashes}" src="{$purl}/t2/{$p.p3}?{$smarty.now}" /></div>{/if}

Please help.

There are peaces of code in your javascript that (I think) are not javascript, Smarty tags perhaps? Tthe firebug console launches an error there.

{/literal}
{if $p.p2 ne ""}
{literal}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM