LoginSignup
1
3

Laravel で jQuery を使う

Last updated at Posted at 2018-06-19

次のプログラムを改造して、jQuery を使います。
Laravel で HelloWorld

  1. resources/views/hello.blade.php を改造
  2. hello.blade.php
    <!DOCTYPE html>
    <html lang="ja">
    <head>
      <meta charset="UTF-8">
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
    <script type="text/javascript" src="js/ex01.js"></script>
      <title>My First Page</title>
    </head>
    <body>
      <h2>Hello World!!</h2>
      <p>皆さんこんにちは</p>
    <hr />
    <div id="outarea_aa">outarea_aa</div>
    <div id="outarea_bb">outarea_bb</div>
    <div id="outarea_cc">outarea_cc</div>
    <div id="outarea_dd">outarea_dd</div>
    <div id="outarea_ee">outarea_ee</div>
    <div id="outarea_ff">outarea_ff</div>
    <div id="outarea_gg">outarea_gg</div>
    <div id="outarea_hh">outarea_hh</div>
    <hr />
    <p>Dec/16/2023</p>
    </body>
    </html>
    
    
  3. スクリプト public/js/ex01.js を作成
  4. mkdir public/js
    
    public/js/ex01.js
    // -----------------------------------------------------------------------
    //      ex01.js
    //
    //                                      Dec/16/2023
    //
    // -----------------------------------------------------------------------
    jQuery (function ()
    {
            jQuery("#outarea_aa").text ("*** ex01.js *** start ***")
    
            jQuery("#outarea_bb").text ("*** Dec/16/2023 AM 09:33 ***")
    
            jQuery("#outarea_hh").text ("*** ex01.js *** end ***")
    })
    // -----------------------------------------------------------------------
    
  5. サーバーを起動
  6. php artisan serve --host 0.0.0.0
    
  7. ブラウザーで http://localhost:8000/hello にアクセス
  8. image.png

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3