2014-08-29 56 views
1

我有一個假的訪問者的計數器腳本,其中的JavaScript代碼,但我想在smarty tpl文件中使用它,我嘗試去做,但沒有顯示我想要的位置。腳本代碼低於如何在smarty tpl中使用javascript功能

<!--Simply copy and paste it where you wish the counter to appear.--> 


<SCRIPT language="JavaScript" type="text/javascript"> 
// counter - from http://rainbow.arch.scriptmania.com/scripts 
function fakecounter(){ 

//decrease/increase counter value (depending on perceived popularity of your site!) 
var decrease_increase=2460 

var counterdate=new Date() 
var currenthits=counterdate.getTime().toString() 
currenthits=parseInt(currenthits.substring(2,currenthits.length-4))+decrease_increase 

document.write("You are visitor # <b>"+currenthits+"</b> to my site!") 
} 
fakecounter() 
</script> 

我試圖在</script>之後使用它。

回答

1

此腳本應該沒有問題。如果你把它放在乾淨的Smarty模板文件中,你會得到類似於以下的信息:

您是訪客#945155我的站點!

然而,在舊版本,你需要使用{literal}使用JavaScript智者的,所以你的代碼應該是這樣的:

<!--Simply copy and paste it where you wish the counter to appear.--> 


<SCRIPT language="JavaScript" type="text/javascript"> 
    {literal} 
    // counter - from http://rainbow.arch.scriptmania.com/scripts 
    function fakecounter() { 

//decrease/increase counter value (depending on perceived popularity of your site!) 
     var decrease_increase = 2460 

     var counterdate = new Date() 
     var currenthits = counterdate.getTime().toString() 
     currenthits = parseInt(currenthits.substring(2, currenthits.length - 4)) + decrease_increase 

     document.write("You are visitor # <b>" + currenthits + "</b> to my site!") 
    } 
    fakecounter() 
    {/literal} 
</script>