简体   繁体   English

我如何在Jquery代码中包含@include('layout.example')?

[英]how do i include @include('layout.example') in Jquery code?

So if i have a small layout stored in example.blade.php, How do i use it in jquery ? 因此,如果我在example.blade.php中存储了一个小的布局,那么如何在jquery中使用它?

I want to include certain elements such as textboxes when a particular radio button is checked otherwise not. 我想在选中某个单选按钮时包括某些元素,例如文本框,否则不选中。

Example: 例:

$("document").ready(function(){

    if ($("#role").prop( "checked")) {
        $("#content").html(@include('layouts.nav'));
    }
    else
    {
        $("#content").html('');
    }

});

The above code does not work so please provide some solution. 上面的代码不起作用,因此请提供一些解决方案。

You can not do that. 你不能这样做。 @include() is Blade and will be interpreted by PHP while JS runs in the browser. @include()是Blade,当JS在浏览器中运行时将由PHP解释。 The Blade directives are already interpreted by PHP when the code hits the browser 当代码到达浏览器时,PHP已经解释了Blade指令

You can create a hidden div in your view and then use jquery to get it's html content, here is an example: 您可以在视图中创建一个隐藏的div,然后使用jquery来获取它的html内容,这是一个示例:

<div class="layouts-nav" style="display:none;">
    @include('layouts.nav')
</div>

<script>

    $("document").ready(function(){

        if ($("#role").prop( "checked")) {

            var layoutNav = $('#layouts-nav').html();
            $("#content").html(layoutNav);
        }
        else
        {
            $("#content").html('');
        }

    });

<script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM