我想插入jQuery插件http://thefinishedbox.com/freebies/scripts/jquery-dropdown-login/使我的网站更漂亮,但我真的很困惑在哪里和如何插入jQuery到我的代码。例如,下面是我的index.php
<?php
include ('book_fns.php');
session_start();
do_html_header("Welcome to Store");
echo "<p>Please choose a category:</p>";
// Get categories out of database
$cat_array = get_categories();
// Display as links to cat pages
display_categories($cat_array);
//If logged in as admin, show add, delete, edit cat links.
if(isset($_SESSION['admin_user'])) {
display_button("admin.php", "admin-menu", "Admin Menu");
}
do_html_footer();
?>我想把jQuery插件添加到我的索引页面的顶部。
如何插入这个jQuery插件?
发布于 2011-11-27 08:29:21
直接从CDN那里得到。将此代码粘贴到页面的头上:
<HTML>
<HEAD>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</HEAD>
</HTML>然后,就像使用常规javascript代码一样使用库,就像下面这样:
<script>
$(document).ready(function() {
alert('Hey! I was called when the document finished loading.');
});
</script>发布于 2011-11-27 08:27:31
我认为您应该将标记回索引页面,如下所示:
echo "<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>"或者在标记中包含包含jQuery脚本的HTML/PHP文件。
include('headScript.php');或者编写一个与上面的标记相呼应的函数:
echo $this->headScript("http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js");
protected function headScript($src){
return '<script type="text/javascript" src="$src"></script>';
}发布于 2011-11-27 08:19:44
是的,只要像对待HTML那样对待JavaScript和jQuery代码即可。服务器读取PHP代码,PHP代码告诉服务器要向浏览器发送什么,浏览器是读取jQuery和HTML的内容。
https://stackoverflow.com/questions/8284386
复制相似问题