当我尝试将jquery脚本添加到smarty tpl文件时出了什么问题?

时间:2011-02-08 09:16:43

标签: php javascript jquery smarty

它给了我空白页......

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
{if $tplSeoFile}{include file="$modulePath/$tplSeoFile"}{/if}   
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Author" content="" />
<meta name="Robots" content="index, follow" />
<meta name="Revisit-after" content="10 days" />
<link rel="stylesheet" href="img/cms/css/reset.css" type="text/css" media="all" />
<link rel="stylesheet" href="img/cms/css/960.css" type="text/css" media="all" />
<link rel="stylesheet" href="img/cms/css/master.css" type="text/css" media="all" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {

    //Default Action
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content

    //On Click Event
    $("ul.tabs li").click(function() {
        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content
        var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active content
        return false;
    });

});
</script>


</head>

3 个答案:

答案 0 :(得分:3)

您需要将其括在{literal}标记中,否则smarty会尝试解释JavaScript代码中花括号内的内容,从而导致灾难性故障并可能出现白页死亡:

{literal}
<script>
$(document).ready(function() {

    //Default Action
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content

    //On Click Event
    $("ul.tabs li").click(function() {
        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content
        var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active content
        return false;
    });

});
</script>
{/literal}

请参阅http://www.smarty.net/docsv2/en/language.function.literal.tpl

答案 1 :(得分:2)

我宁愿使用{literal} {/ literal},也更容易。

答案 2 :(得分:0)

陈述here您需要将代码带到外部JS脚本或使Jquery处于noconflict模式! 它很简单,用jQuery('')改变$('')