如何将 jQuery 插件插入 PHP 代码?

发布于 2024-12-18 08:32:20 字数 802 浏览 0 评论 0原文

我想插入 jQuery 插件下拉登录表单 让我的网站更漂亮,但我真的很困惑在哪里以及如何将 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 插件?

I want to insert the jQuery plugin dropdown login form to make my website more pretty, but I am really confused where and how to insert jQuery into my code. For instance the following is my 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();
?>

And I want to add the jQuery plugin to the top of my index page.

How do I insert this jQuery plugin?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

揽清风入怀 2024-12-25 08:32:20

直接从 CDN 获取。将此代码粘贴到页面的 HEAD 上:

<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>

Get it straight from the CDN. Paste this code on your page's HEAD :

<HTML>
   <HEAD>    
   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
   </HEAD>
</HTML>

Then utilize the library just as you would with your usual javascript code just like this one:

<script>
    $(document).ready(function() {
      alert('Hey! I was called when the document finished loading.');
    });
</script>
尾戒 2024-12-25 08:32:20

我认为您应该将标签回显到索引页,如下所示:

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>';
}

I think you should echo the tag to your index page like this:

echo "<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>"

Or you include an HTML/PHP file that contains jQuery script in the <head></head> tag

include('headScript.php');

Or you write a function that echo the <script></script> tag above:

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>';
}
水中月 2024-12-25 08:32:20

是的,只需像对待 HTML 一样对待 JavaScript 和 jQuery 代码即可。服务器读取 PHP 代码,PHP 代码告诉服务器将什么发送到浏览器,然后浏览器读取 jQuery 和 HTML。

Yes, just treat the JavaScript and jQuery code as you would HTML. The server reads the PHP code and the PHP code tells the server what to send to the browser, and the browser is what reads the jQuery and HTML.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文