Handling PHP with jQuery .html()


Handling PHP with jQuery .html()

我正在尝试让jQuery更改元素的html并包含PHP。除了PHP之外,一切都很好。这是我所拥有的:

$('.gridheader').each(function(index){
    $(this).toggle(function (){
        $('.gridimage:eq('+index+'), .gridinfo:eq('+index+')').slideToggle();
        $('.gridheadinfo:eq('+index+')').html('Click to close <img src="<?php echo base_url() ?>/assets/images/closetab.png" width="10" height="10" />');
    }, function(){
        $('.gridimage:eq('+index+'), .gridinfo:eq('+index+')').slideToggle();
        $('.gridheadinfo:eq('+index+')').html('Click for info <img src="<?php echo base_url() ?>/assets/images/scrollup.png" width="11" height="10" />');
    });
});

我有最初的图像在那里(HTML):

<div class="float-left">Kredible</div><div class="float-right gridheadinfo">Click for info <img src="<?php echo base_url() ?>assets/images/scrollup.png" width="11" height="10" /></div></div>

HTML运行良好,但是当我使用jQuery更改它时,图像不会显示。我在更改后的检查器中查看了它,PHP显示为PHP,而不是转换为HTML?

我很困惑。

谢谢。

保存服务器端变量,然后使用它:

      var url="<?php echo base_url() ?>"; 
    //this will be parsed by the php interpreter at page load so url will be "localhost/subdomain/" probably. 
        $('.gridheader').each(function(index){
            $(this).toggle(function (){
                $('.gridimage:eq('+index+'), .gridinfo:eq('+index+')').slideToggle();
                $('.gridheadinfo:eq('+index+')').html('Click to close <img src="'+url+'/assets/images/closetab.png" width="10" height="10" />');
    //use it here
            }, function(){
                $('.gridimage:eq('+index+'), .gridinfo:eq('+index+')').slideToggle();
                $('.gridheadinfo:eq('+index+')').html('Click for info <img src="'+url+'/assets/images/scrollup.png" width="11" height="10" />');
            });
        });

包含php文件只会在服务器上影响html。

因此,更改后的代码不会有任何影响,因为php脚本没有执行。

你可以加载一个html文件的内容,然后把它放进你的页面。当然,SQL在内部是不可能的。