开发者

PHP rendering JS useless

Ok, so, I'm not at all familiar with PHP dev, however, here I find myself. I have a page I created in HTML/CSS and JS that works great with several JS plugins. However, when I turn it into a php page, the JS is conflicting and rendered useless.

It is because the PHP is aggregating it into one large js file. When I run it in debug and loading up all the files separately everything is fine. Has anyone hit this before?

Here is how I am loading them:

register_script( array(

    'base_path' =>  PROJECTURL,
    'scripts'    => 开发者_Go百科array(
        'js/libs/jquery-1.5.min.js',
        'js/libs/jquery.jscrollpane.js',
        'js/libs/jquery.selectbox-0.6.1.js',
        'js/libs/jquery.mousewheel.js',
            'js/libs/jquery.autocomplete.min.js',
        'js/libs/jquery.watermark.js', 
                'js/propriatary-name.js',

    )

) ); 


I don't think your register_script function is doing what you expect. This is not a standard PHP function, so unless you are using a framework, you need to change some things.

Your PHP gets executed server side, while your .js files are inluded in the DOM on the client side. If you're doing this programatically, just add your scripts to an array, then add the scripts to your HTML output with a foreach loop:

$pagescripts = array(
        'js/libs/jquery-1.5.min.js',
        'js/libs/jquery.jscrollpane.js',
        'js/libs/jquery.selectbox-0.6.1.js',
        'js/libs/jquery.mousewheel.js',
        'js/libs/jquery.autocomplete.min.js',
        'js/libs/jquery.watermark.js', 
        'js/propriatary-name.js');

foreach($pagescripts[$page] as $v){
    $output .= "<script type=\"text/javascript\" src=\"" . $v . "\"></script>\n";
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜