当我添加jquery验证函数时,我的其他函数停止工作

When I add jquery validate function my other functions stop working

本文关键字:函数 我的 其他 停止工作 添加 jquery 验证      更新时间:2023-09-26

我有一个表单,我有几个javascript/jquery函数工作良好。只要我添加一个验证函数,它们就都停止工作了。我使用的插件从http://jqueryvalidation.org/和有我所有的功能在一个js文件。在添加验证函数之前,所有这些函数都能正常工作。这是js文件。

$(function(){
        $(".timeinput").timepicker({
          step: 5  
        });
    });
  $(function(){
            $(".datepick").datepicker({
                changeYear: true,
                changeMonth: true
            });
        });

  $(function(){
    $("#incimechtype").change(function(){
        var dropdown = $(this).val();
        $.ajax({
             url:"getinjuryjson.php",
             dataType: "json"  
        }).done( function(data){
             $("#incimech").find("option").remove();
             if(dropdown !== ""){
                $("#incimech").append($('<option/>'));
             }
             switch(dropdown){
                    case "Mechanism":
                        $.each(data, function(key,value){
                            if(value.injmech==='Mechanism'){
                                $("#incimech").append($('<option/>',{
                                value: value.injmechid,
                                text: value.injmechdescrip
                                }));
                                }
                        });
                        break;
                    case "Other":
                        $.each(data, function(key,value){
                            if(value.injmech==='Other'){
                                $("#incimech").append($('<option/>',{
                                value: value.injmechid,
                                text: value.injmechdescrip
                                }));
                                }
                        });
                        break;
                    case "Object":
                        $.each(data, function(key,value){
                            if(value.injmech==='Object'){
                                $("#incimech").append($('<option/>',{
                                value: value.injmechid,
                                text: value.injmechdescrip
                                }));
                                }
                        });
                        break;
                    }
        }
        )
    }
    ) 
  }
  );
    $("#referto").change(function(){
        var rechange = false;
        $('#referto option:selected').each(function(){
            if($(this).text()=="Other"){
                rechange =true;
            }
        });
        if(rechange){
             var textarea = "<textarea name='referother' id='referother' />";
            $("#referto").after(textarea);
        }
        else
        {
            $("#referother").remove();
        } 
    });
  $(function(){
    $("#classcase").change(function(){
        var dropdown = $(this).val();
         $.ajax({
             url:"getoshaclassson.php",
             dataType: "json"  
        }).done( function(data){
             $("#otherrecord").find("option").remove();
             if(dropdown !== ""){
                $("#otherrecord").append($('<option/>'));
             }
             if(dropdown ==="Other Recordable"){
                $.each(data, function(key,value){
                            if(value.oshaclassid > 3){
                                $("#otherrecord").append($('<option/>',{
                                value: value.oshaclassid,
                                text: value.oshaclass
                                }));
                                }
                        });
             }
        }
        )
    }
    ) 
  }
  );

 $(function(){
     $("#addlostdays").click(function(){
     $("#oshadataarea").find("label").remove();
     $("#oshadataarea").find("input").remove();
     $("#oshadataarea").find("textarea").remove();
     $("#oshadataarea").find("br").remove();
    $("#oshadataarea").append($('<label/>',{
        text:"Begin Lost Date",
        for: "newloststartdate",
        class: "eighth"})).append($('<input/>',{
            type: "text",
            id: "newloststartdate",
            name: "newloststartdate",
            class:"datepick"
        })).append($('<label/>',{
        text:"End Lost Date",
        for: "newlostenddate",
        class: "eighth"})).append($('<input/>',{
            type: "text",
            id: "newlostenddate",
            name: "newlostenddate",
            class:"datepick"
        }))
  });
  $('form').on('focus',".datepick", function(){
    $(this).datepicker({
        changeMonth: true,
        changeYear: true
    });
    });
 });

$(function(){
     $("#addjobtrans").click(function(){
     $("#oshadataarea").find("label").remove();
     $("#oshadataarea").find("input").remove();
      $("#oshadataarea").find("textarea").remove();
     $("#oshadataarea").find("br").remove();
    $("#oshadataarea").append($('<label/>',{
        text:"Begin Light Duty",
        for: "newlightstartdate",
        class: "eighth"})).append($('<input/>',{
            type: "text",
            id: "newlightstartdate",
            name: "newlightstartdate",
            class:"datepick"
        })).append($('<label/>',{
        text:"End Light Duty",
        for: "newlightenddate",
        class: "eighth"})).append($('<input/>',{
            type: "text",
            id: "newlightenddate",
            name: "newlightenddate",
            class:"datepick"
        }))
  });
  $('form').on('focus',".datepick", function(){
    $(this).datepicker({
        changeMonth: true,
        changeYear: true
    });
});
 });
 $(function(){
     $("#addemphealthcomments").click(function(){
     $("#oshadataarea").find("label").remove();
     $("#oshadataarea").find("input").remove();
     $("#oshadataarea").find("textarea").remove();
     $("#oshadataarea").find("br").remove();
    $("#oshadataarea").append($('<label/>',{
        text:"Employee Comment Date",
        for: "newemplcomdate",
        class: "eighth"})).append($('<input/>',{
            type: "text",
            id: "newemplcomdate",
            name: "newemplcomdate",
            class:"datepick"
        })).append($('<br />')).append($('<label/>',{
        text:"Employee Comments",
        for: "newemplincidomments",
        class: "eighth"})).append($('<textarea/>',{
            cols: "50",
            rows: "5",
            id: "newemplincidomments",
            name: "newemplincidomments"
        }))
  });
 });

一旦我在下面添加了这个函数,其他的函数就会停止工作。

$function(){
    $("#incidentform").validate({
        rules: {
            incidate: "required"
        },
        messages: {
            incidate: "Please enter the incident date."
        }
    })
 }
我一定是做错了什么。说到jquery,我几乎是一个新手,因为我只使用了一个月。希望有人能帮忙。
$(function(){
    $("#incidentform").validate({
        rules: {
            incidate: "required"
        },
        messages: {
            incidate: "Please enter the incident date."
        }
    })
 });

缺少括号