web.py在模板中输出美元符号的方法

WBOY
Release: 2016-06-16 08:42:33
Original
1515 people have browsed it

由于web.py已经在模板中定义“$”符号位定界符,所以在模板中如果要使用美元符号需要特殊处理。

如我要在模板中输出“$name”字符串:

复制代码 代码如下:

$name

报错

$name被认定为一个变量而不是当作HTML字符串处理。如果想要输出“$name”字符串必须要这么写:

复制代码 代码如下:

$$name

保存运行正确输出。
特别是跟jQuery里混合使用的时候,也要注意。如:
复制代码 代码如下:
$("id").html("脚本之家");
要修改成:
复制代码 代码如下:
$$("id").html("脚本之家");
这样才可以使用。
因为Python是服务器端语言,而JS是客户端语言。服务器端语言最终把:
复制代码 代码如下:

$$("id").html("脚本之家");

翻译成:
复制代码 代码如下:

$("id").html("脚本之家");

然后丢给客户端,而不是jQuery可以使用双美元符号“$$("id")”,概念不要搞错。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!