未捕获的TypeError:form.steps不是函数

时间:2016-06-13 17:49:45

标签: javascript html angularjs forms

我正在尝试为我的表单创建一个简单的向导。但它会给我“CursusWizard.js:3 Uncaught TypeError:form.steps不是函数”错误。

我也是第一次使用Angular,我想也许这与我的javascript无法正常工作有关。

这是我的html表单:

 <!DOCTYPE html>
 <html lang="en">

 <head>

<meta charset="UTF-8">
    <title> Cursus </title>
  </head>

 <form id="example-advanced-form" class="form-horizontal" name="form" action="#" ng-submit="addCursus()">
 <h3>Cursus aanmaken</h3>
    <fieldset>
    <legend> Cursus informatie</legend>

  <label for ="naam"> Cursus naam</label>
    <input id="naam" name="naam" type="text" class="required" ng-model="formCursus.name">


    <label for ="cursuscode"> Cursus code</label>
    <input id="cursuscode" name="cursuscode" type="text" class="required" ng-model="formCursus.cursuscode">


    <label for ="aantalec">Aantal ec </label>
    <input name="aantalec" type="text" list="aantalec" class="required" ng-model="formCursus.aantalec">
    <datalist id="aantalec">
        <option value="Boston">
        <option value="Cambridge">
    </datalist>

    <label for ="periode">Periode </label>
    <input name="periode" type="text" list="periode" class="required" ng-model="formCursus.periode">
    <datalist id="periode">
        <option value="Boston">
        <option value="Cambridge">
    </datalist>

<button class="btn-default" type="submit">Add</button>

    <p>(*) Mandatory</p>
</fieldset>


<h3>Profile</h3>
<fieldset>
    <legend>Profile Information</legend>

    <label for="name-2">First name *</label>
    <input id="name-2" name="name" type="text" class="required">
    <label for="surname-2">Last name *</label>
    <input id="surname-2" name="surname" type="text" class="required">
    <label for="email-2">Email *</label>
    <input id="email-2" name="email" type="text" class="required email">
    <label for="address-2">Address</label>
    <input id="address-2" name="address" type="text">
    <label for="age-2">Age (The warning step will show up if age is less than 18) *</label>
    <input id="age-2" name="age" type="text" class="required number">
    <p>(*) Mandatory</p>
</fieldset>

<h3>Warning</h3>
<fieldset>
    <legend>You are to young</legend>

    <p>Please go away ;-)</p>
</fieldset>

<h3>Finish</h3>
<fieldset>
    <legend>Terms and Conditions</legend>

    <input id="acceptTerms-2" name="acceptTerms" type="checkbox" class="required"> <label for="acceptTerms-2">I agree with the Terms and Conditions.</label>
</fieldset>

</form>
  </html>

以下是我的javascript代码:

    var form = $("#example-advanced-form").show();

    form.steps({
headerTag: "h3",
bodyTag: "fieldset",
transitionEffect: "slideLeft",
onStepChanging: function (event, currentIndex, newIndex)
{
    // Allways allow previous action even if the current form is not valid!
    if (currentIndex > newIndex)
    {
        return true;
    }
    // Forbid next action on "Warning" step if the user is to young
    if (newIndex === 3 && Number($("#age-2").val()) < 18)
    {
        return false;
    }
    // Needed in some cases if the user went back (clean up)
    if (currentIndex < newIndex)
    {
        // To remove error styles
        form.find(".body:eq(" + newIndex + ") label.error").remove();
        form.find(".body:eq(" + newIndex + ") .error").removeClass("error");
    }
    form.validate().settings.ignore = ":disabled,:hidden";
    return form.valid();
},
onStepChanged: function (event, currentIndex, priorIndex)
{
    // Used to skip the "Warning" step if the user is old enough.
    if (currentIndex === 2 && Number($("#age-2").val()) >= 18)
    {
        form.steps("next");
    }
    // Used to skip the "Warning" step if the user is old enough and wants to the previous step.
    if (currentIndex === 2 && priorIndex === 3)
    {
        form.steps("previous");
    }
},
onFinishing: function (event, currentIndex)
{
    form.validate().settings.ignore = ":disabled";
    return form.valid();
},
onFinished: function (event, currentIndex)
{
    alert("Submitted!");
}
 }).validate({
errorPlacement: function errorPlacement(error, element) { element.before(error); },
rules: {
    confirm: {
        equalTo: "#password-2"
    }
}
});

我做错了什么?

2 个答案:

答案 0 :(得分:0)

var form = $("#example-advanced-form").show();

你将.show()返回的值分配给变量form,据我所知,在jquery中.show()不会返回任何值,所以表单可能没有方法方法step()和引用form.step()将导致错误。

答案 1 :(得分:0)

您是否包含用于步骤功能的jquery cdn? 请参考下面的CDN链接,尝试通过添加CDN执行并在添加后发布您的发现。 “ https://cdnjs.cloudflare.com/ajax/libs/jquery-steps/1.1.0/jquery.steps.min.js

快乐的编码!