php通过smarty传递给html的变量该如何存储
在html中,有php通过smarty传递过来的一个变量,比如用户的性别(sex),如果是男性我会用js去做一些操作。如果是女性则会去做另一些操作。一般的写法如下:
<script type='text/javascript' >
<{ if $sex == 'male'}>
var xxxx=123;
do_some_thing(); //可能操作比较复杂
<{ else }>
var yyyy=456;
do_other_thing(); //可能操作比较复杂
<{ /if }>
</script>
但是在html里面直接写js很影响页面的加载。
不知道有没有别的办法去执行那段js。而且那段js里有smarty变量,对js的修改和维护带来的不少的麻烦。
想过把sex这个变量用<input type='hidden' id=user_sex value='<{$sex}>' /> 来存储,然后需要的时候再document.getElementById('user_sex'): 。但是哪一天这个sex变量名称变了,或者取消了,那还得去搜索出input元素,然后把它删掉,这样觉得很别扭。
不知道大牛们有啥好的方法。
<script type='text/javascript' >
<{ if $sex == 'male'}>
var xxxx=123;
do_some_thing(); //可能操作比较复杂
<{ else }>
var yyyy=456;
do_other_thing(); //可能操作比较复杂
<{ /if }>
</script>
但是在html里面直接写js很影响页面的加载。
不知道有没有别的办法去执行那段js。而且那段js里有smarty变量,对js的修改和维护带来的不少的麻烦。
想过把sex这个变量用<input type='hidden' id=user_sex value='<{$sex}>' /> 来存储,然后需要的时候再document.getElementById('user_sex'): 。但是哪一天这个sex变量名称变了,或者取消了,那还得去搜索出input元素,然后把它删掉,这样觉得很别扭。
不知道大牛们有啥好的方法。
...全文
相关推荐
php smarty
界面简洁.....整齐....编码规范..........比较适合初学者使用!!
php中用smarty做的留言板
smarty做的留言板,大家参考下,高手路过,给新手看的,这个只是简单的应用功能
php模版 (smarty)php模版 (smarty)php模版 (smarty)
php模版 (smarty)php模版 (smarty)php模版 (smarty)php模版 (smarty)php模版 (smarty)php模版 (smarty)php模版 (smarty)
php smarty图书管理系统。。
php图书管理系统。。是用smarty做的。。做的有点简陋。。大家将就着看吧。。绝对原创。。。。
PHP 开发 典型模块大全 smarty模板
PHP 开发 典型模块大全 smarty模板 留言本


基础编程
