【问题标题】:The code I typed on the button does not work /laravel8我在按钮上输入的代码不起作用 /laravel 8
【发布时间】:2022-11-24 20:32:48
【问题描述】:

我想制作一个按钮,在按下时发出提醒(消息),但该按钮不起作用。 按钮的代码在母版页中

(我把剩下的两页写在了cmets中,因为当我在帖子中写的时候出现了错误)

这是我的 master.blade.php;

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>E-Comm Project</title>

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

</head>
<body>
    
</body>
<script>
    $(document).ready(function())
    {
      $("button").click(function())
       {
         alert("button works correctly")
       }
    }
</script>
</html>

【问题讨论】:

  • 那是 web.php 页面 <?php use Illuminate\Support\Facades\Route; Route::get('/', function () { return view('login'); }); .thats 登录页面 @extends('master') @section('content') @endsection <h1>Hello,world</h1> <button class="btn btn-primary">点击</button>
  • 您需要了解更多有关Laravel Blade TemplateExample of how to use的信息

标签: php html laravel laravel-8


【解决方案1】:

我认为您需要在 master.blade.php 中添加对内容部分的引用。像下面这样的东西!

 <body>
  @yield('content')
 </body>

而 login.blade.php 将如下所示。

@section('content') <h1>Hello,world</h1> <button class="btn btn-primary">Click</button> @endsection 

附言:https://laravel.com/docs/5.0/templates

【讨论】:

    【解决方案2】:

    主页上的@yeild() 方法在哪里。正如上面的评论所提到的。 我们需要有关该问题的更多信息。 我在共享的 sn-p 中没有看到任何按钮元素。

    【讨论】:

    • 我在 cmets 中写了按钮元素,但我没有写 @yield(),因为我正在看视频来做这个,他没有显示 yield 在哪里
    【解决方案3】:

    在您的 master.blade.php 中添加以下内容:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>E-Comm Project</title>
    
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    
    <script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
    
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    
    </head>
    <body>
        @yield('content')
    </body>
    <script>
        $(document).ready(function(){
            $(document).on('click', 'button', function(event){
                alert("button works correctly");
            });
        });
    </script>
    </html>
    

    以及您的 login.blade.php 中的以下内容

        @extends('master')
    @section('content')
    <h1>Hello,world</h1> 
    <button class="btn btn-primary">Click</button>
    @endsection
    

    【讨论】:

      【解决方案4】:

      你的@yeild()方法在哪里?你不写它?

      【讨论】:

      猜你喜欢
      • 2015-11-08
      • 2021-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多