JS没有在laravel内容刀片标签内运行

I run this code: source: http://jqueryui.com/datepicker/#show-week. I am running laravel php framework

When I clear everything in the route and just past the code it works!

BUT

When i put it inside content..... @extends('layouts.app') @section('content') and @endsection it stops working.

  • Both when i past the ENTIRE code as it is.
  • And also when i insert just the js and css into the header within the layouts app extension

What is going wrong? no error in console. the files are being loaded

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Datepicker - Show week of the year</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#datepicker" ).datepicker({
      showWeek: true,
      firstDay: 1
    });
  } );
  </script>
</head>
<body>

<p>Date: <input type="text" id="datepicker"></p>


</body>
</html>

Try putting JS in your layouts.app after the body tag and then extend it to the required page.

  • Do not forget to put @endsection at the end of the section.
  • Also, check your code by inspect tool. Detect where your scripts are loading and confirm that they are included at the end of the page.