gpt4 book ai didi

javascript - 如何在 smarty tpl 中使用 javascript 函数

转载 作者:行者123 更新时间:2023-11-28 01:01:20 25 4
gpt4 key购买 nike

我有一个假访客计数器脚本,它用 javascript 编码,但我想在 smarty tpl 文件中使用它,我尝试这样做,但它没有显示在我想要的位置。脚本代码如下

<!--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> 之后使用它.

最佳答案

这个脚本应该可以正常运行。如果您将其放入干净的 Smarty 模板文件中,您将获得类似于以下内容的信息:

You are visitor # 945155 to my site!

但是,在旧版本的 smarty 中,您需要使用 {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>

关于javascript - 如何在 smarty tpl 中使用 javascript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25577588/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com