Yii框架中使用jquery的有关问题

WBOY
Release: 2016-06-13 13:47:17
Original
1167 people have browsed it

Yii框架中使用jquery的问题!
Yii框架下的protected/views/site/index.php,一个非常简单的页面

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php Yii::app()->clientScript->registerCoreScript(Yii::app()->request->baseUrl.'/protected/views/site/jquery.js');
Yii::app()->clientScript->registerCoreScript(Yii::app()->request->baseUrl.'/protected/views/site/1.js');
?>

 <p>123</p>
 <button>hide</button>

Copy after login

可是jquery效果完全显示不了,我将文件移出Yii框架的文件夹,独立运行,并把代码改成如下
PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="1.js"></script>
<p>123</p>
 <button>hide</button>

Copy after login

效果可以显示,证明js文件没问题,请问在Yii中怎样有效使用jquery呢?


------解决方案--------------------
具体看
http://hi.baidu.com/wastorode/blog/item/23bbccf86e0a7d93b901a0b5.html
------解决方案--------------------
有两个地方我个人感觉有问题:
1.registerCoreScript()----手册上是这样写的:
public void registerCoreScript(string $name) 
$name --- the core javascript library name 
就是说这方法应该是用来加载专门的JS库,如jquery;
你要加载你的1.js,应该直接用Yii::app()->clientScript->registerScriptFile()这个方法

2.js文件最好在protect外独立开个js的文件夹放js代码,感觉上会好些
(以上纯属个人看法,不对之处,多多包涵)


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