繁体   English   中英

Javascript代码在刀片模板Laravel中不起作用

[英]Javascript code is not working inside blade template Laravel

我正在使用laravel-5.3。 我正在尝试在刀片模板中放入一些代码。 但似乎JavaScript代码无法正常运行。 这是我的刀片模板。

@extends('layouts.app')
@section('scripts')

    <script type="text/javascript">
        $(document).ready(function() {
            var members = {!!  json_encode($member)  !!};
            var arr = [];
            var cities = new Bloodhound({
                datumTokenizer: Bloodhound.tokenizers.obj.whitespace('text'),
                queryTokenizer: Bloodhound.tokenizers.whitespace,
                local: members
            });
            cities.initialize();
            var elt = $('#researcher');

            elt.tagsinput({
                itemValue: 'value',
                itemText: 'text',
                allowDuplicates: false,
                interactive:true,
                typeaheadjs: {
                    name: 'cities',
                    displayKey: 'text',
                    source: cities.ttAdapter()
                }
            });
            console.log(members);
            var elt1 = $('#advisor');
            elt1.tagsinput({
                itemValue: 'value',
                itemText: 'text',
                allowDuplicates: false,
                interactive:true,
                typeaheadjs: {
                    name: 'cities',
                    displayKey: 'text',
                    source: cities.ttAdapter()
                }
            });

            $("#submit").click(function(event){
                $.ajax({
                    type: "POST",
                    url: '/storeresearch',
                    data: { _token: "{{ csrf_token() }}"},
                    success: function( msg ) {
                        console.log(msg);
                        window.location.replace('/researches');
                    }
                });
            });

        });
    </script>
@endsection

@section('content')
    <form id="hu" action="/storeresearch" method="POST">
        {!! csrf_field() !!}
        <label>Researcher</label>
        <input type="text" class="R_a" id="researcher" name="researchsupervisor_1">
        <label>Advisor</label>
        <input type="text" class="R_a" id="advisor" name="researchsupervisor_1">
        <input type="button" name="submit" id="submit" class="btn btn-primary" value="Add">
    </form>
@endsection

标签输入不起作用。 我该怎么办。 如果我不扩展任何布局就可以正常工作。 在应用程序布局中,我在标题部分产生了脚本部分。

通过检查开发人员选项中的元素来检查代码,查看脚本的加载位置,并确认脚本是否包含在页面末尾。

还要记住使用@endsection标记

暂无
暂无

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

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