这篇文章主要介绍了ThinkPHP控制器里javascript代码不能执行的解决方法,采用ThinkPHP的literal标签来解决javascript标签被解析的问题,是非常实用的技巧,需要的朋
本文实例讲述了ThinkPHP控制器里javascript代码不能执行的解决方法。分享给大家供大家参考。具体方法如下:
这里实例分析一下thinkphp在控制器里的网页特效代码不能执行解决方法,就拿“退出”这一项来说吧,我的“退出系统”链接是写到左边的框架里的,用js动态生成的。也就是说,,没法通过链接里的target来指定。
复制代码 代码如下:
$this->assign('jumpurl',__url__.'/login');
$this->success("注销成功!");
这样写的话,要跳转的页面就显示在了右框架里了,把js代码写到url里面不行,我把这两行代码注释掉了。直接用:
复制代码 代码如下:
echo "<script>window.top.location.href='$url';</script>";
这样也不行,一方面url里面没法用__app__这些常量,另一方面,最后执行出来的结果是竟是把<script>标签去掉,剩下的直接输出!<br /> <p><span>复制代码 代码如下:<p>(window.top.location.href='index/login';)<br /> 我查了action类里的success函数,没有找到相关的参数。 <p>后来突然想到一个问题,tp里的标签都是以尖括号(<>)来包含的,我在控制器里写的<script>是不是被当作标签给解析了呢?于是我就重新写了第二段代码:<br /> <p><span>复制代码 代码如下:<p>echo '<literal><script>alert("退出成功");top.location.href="login";</script>';
这样就行了。
希望本文所述对大家的ThinkPHP框架程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
