关于如何将java脚本变量分配给smarty变量我遇到了问题.这是代码片段.
function getDateInfo(date, wantsClassName)
{
var as_number = Calendar.dateToInt(date); //This as_number is the variable which should be assigned to smarty variable
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点.
任何帮助将不胜感激..
谢谢你提前 - Fero
您不能将客户端值分配给smarty变量,因为smarty是在服务器上运行的模板语言.Smarty分配只能在服务器端完成,也就是说,从PHP完成.例如:
$smarty->assign('timestamp',time());
Run Code Online (Sandbox Code Playgroud)
所以你可以做的是:
$smarty->assign('timestamp',time()); //in your PHP script
//in your JS
var currentTS = {$timestamp};
Run Code Online (Sandbox Code Playgroud)
见http://www.smarty.net/manual/en/api.assign.php