Uncaught TypeError: $(…).steps is not a function

*爱你&永不变心* 提交于 2021-01-24 10:58:38

问题


So I saw really good looking forms in my bootstrap template and I wanted to use them in my project.

I placed all the required files that I think we need to import which are added at the bottom of the code, required files are in the correct directories, for example, jquery steps: C:\xampp\htdocs\rps\public\files\bower_components\jquery.steps\js\jquery.steps.js

'initialize-steps.js':

$("#practitioner-form").steps({
    headerTag: "h3",
    bodyTag: "fieldset",
    transitionEffect: "slideLeft",
    enablePagination: true,
    autoFocus: true,
    onFinished: function (event, currentIndex)
    {
        alert("Practitioner Added!");
    }
});

My HTML file with multiform (...) is skipped part:

<div class="card-block">
        <div class="row">
            <div class="col-md-12">
                <div id="practitioner-form">
                    <form method="post" id="practitioner-form" action="#">
                        <h3>Practitioner</h3>
                        <fieldset>
                            <legend>Practitioner Information</legend>
                            <div class="form-group row">
                                <div class="col-lg-12">
                                    <label for="effective_date" class="block">{{trans('personalData.effectiveDate')}}</label>
                                </div>
                                <div class="col-lg-12">
                                    <input id="effective_date" name="effectiveDate" type="date" class="form-control required">
                                </div>
                            </div>

(...)


<link rel="stylesheet" type="text/css" href="/files/bower_components/jquery.steps/css/jquery.steps.css">
<!-- Required Jquery -->
<script src="/files/js/views/person/initialize-steps.js"></script>
<script src="/files/bower_components/jquery/js/jquery.min.js"></script>
<script src="/files/bower_components/jquery-ui/js/jquery-ui.min.js"></script>
<script src="/files/bower_components/popper.js/js/popper.min.js"></script>
<script src="/files/bower_components/bootstrap/js/bootstrap.min.js"></script>
<!--Forms - Wizard js-->
<script src="/files/bower_components/jquery.cookie/js/jquery.cookie.js"></script>
<script src="/files/bower_components/jquery.steps/js/jquery.steps.js"></script>
<script src="/files/bower_components/jquery-validation/js/jquery.validate.js"></script>

<script src="/files/js/modules/practitionerCompetence.js"></script>

Still when I try to load up the page I get an error: Uncaught TypeError: $(...).steps is not a function Anyone knows how to fix it?


回答1:


jquery.steps.js is loaded way after your initialize-steps.js

<script src="/files/js/views/person/initialize-steps.js"></script>
....
<script src="/files/bower_components/jquery.steps/js/jquery.steps.js"></script>

You need to load initialize-steps.js after it

<script src="/files/bower_components/jquery.steps/js/jquery.steps.js"></script>
<script src="/files/js/views/person/initialize-steps.js"></script>
....



回答2:


Order js like this place your script at end

<script src="/files/bower_components/jquery/js/jquery.min.js"></script>
<script src="/files/bower_components/jquery-ui/js/jquery-ui.min.js"></script>
<script src="/files/bower_components/popper.js/js/popper.min.js"></script>
<script src="/files/bower_components/bootstrap/js/bootstrap.min.js"></script>
<!--Forms - Wizard js-->
<script src="/files/bower_components/jquery.cookie/js/jquery.cookie.js"></script>
<script src="/files/bower_components/jquery.steps/js/jquery.steps.js"></script>
<script src="/files/bower_components/jquery-validation/js/jquery.validate.js"></script>

<script src="/files/js/modules/practitionerCompetence.js"></script>
<script src="/files/js/views/person/initialize-steps.js"></script>


来源:https://stackoverflow.com/questions/56560467/uncaught-typeerror-steps-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!