LigerUi驗證

方式一:類似於一下這種驗證

    <script type="text/javascript">

    //------------------------------------dml相關操作-----------------------------------------------

      var CurID = 1;

        var Validator = null;[d1] 

        var editor_description;  

        $(function ()

        {         

           $("#infoform").ligerForm();

           //驗證信息

           $.metadata.setType("attr", "validate");

           deafultValidate($("#infoform"));

           Validator = $("#infoform").validate();

[d2] [d3]            $("#title").focus();

        });      

      function f_success() {

     $.ligerDialog.closeWaitting();

      $.ligerDialog.success("保存成功","",function(button,domobject,buttonindex){

       top.frames["TabArticle"].f_reload();

       LG.closeCurrentTab('TabArticleModify');

   

     });

     }

        function f_error(message)

        {

            $(document).ready(function(){

                $.ligerDialog.error(message);

            });

        }

         //按鈕提交

      function f_post(){   

      var nid=$("#nid").val();

      var rootid=$("#rootid").val();

            var options = {

            target:'',

            url:'article!save.action?nid='+nid, 

            type:'POST',

            success: function(data,textStatus){

            if(data=='false'){

               $.ligerDialog.closeWaitting();

               $.ligerDialog.error("保存失敗");

            }else if(data=='true'){

                f_success();

            }

            }};

            $('#infoform').ajaxSubmit(options);

      }

     

        function f_save()

        {       

         if(!Validator.form()) return;

             $("form").ligerForm();

[d4]             

          editor_description.sync(); 

            $.ligerDialog.waitting("正在保存中...");

             setTimeout(function(){

                f_post();

            },10);

        }

      

    </script>

   <style type="text/css">

 

    body{ font-size:12px;padding:20px;}

        .l-table-edit {}

        .l-table-edit-td{ padding:4px;}

        .l-button-submit,.l-button-test{width:80px; float:left; margin-left:10px; padding-bottom:2px;}

        .l-verify-tip{ left:230px; top:120px;}

    </style>

 

  </head>

 

  <body>

    <div>

   <form id="infoform" action="" method="post" >

   <input type="hidden" name="articleid" id="articleid" value="${articleid}"/>

    <input type="hidden" id="nid"  value="${nid}"/>

    <input type="hidden" name="rootid" id="rootid" value="${rootid}"/>

  

       

         <table cellpadding="0" cellspacing="0" class="l-table-edit"  align="left"  >          

            <tr>

                <td  class="l-table-edit-td">標題:</td>

               <td   class="l-table-edit-td"  colspan="2"><input  ligerui="{width:600}" name="title" value="${title}" type="text" id="title" 

                validate="{required:true,minlength:1,maxlength:50}" [d5] /></td>               

                <td align="left"><font color="red">*</font></td>

            </tr>

           <tr>

                <td  class="l-table-edit-td">摘要:</td>

                <td class="l-table-edit-td" style="width:600px" colspan="2">

                <textarea cols="100" rows="5" class="l-textarea" id="abstract_" name="abstract_" style="width:600px"

                validate="{required:true,minlength:1,maxlength:100}" >${abstract_}</textarea>

               </td>

                <td align="left"><font color="red">*</font></td>

            </tr>

           <tr>

                <td class="l-table-edit-td" valign="top">首頁顯示</td>

                <td  class="l-table-edit-td" style="width:160px">

                    <input id="rbtnl_0" type="radio" name="isnotice" value="1"  <c:if test="${isnotice==1}">checked</c:if> /><label for="rbtnl_0"></label>&nbsp;&nbsp;&nbsp;&nbsp;

                  <input id="rbtnl_1" type="radio" name="isnotice" value="0"  <c:if test="${isnotice==0||isnotice==''}">checked</c:if>/><label for="rbtnl_1"></label>

                </td>              

                <td class="l-table-edit-td" style="width:160px"></td>

                <td align="left"></td>

            </tr>  

           <tr>

                <td class="l-table-edit-td">正文:</td>

                <td  class="l-table-edit-td" colspan="2">               

                <textarea id="editor_description" name="content" style="width:600px;height:300px;">${content}</textarea>

                </td>

                <td align="left"></td>

            </tr>     

        </table>

          

   </form>

   </div>

 

      <script type="text/javascript">

     $(function() {

     KindEditor.ready(function(K) {

      editor_description = K.create('#editor_description', {

      resizeType : 0, //2102時可以拖動改變寬度和高度,1時只能改變高度,0時不能拖動。

      allowPreviewEmoticons : false,//true時鼠標放在表情上可以預覽表情。

      allowImageUpload : false,

      items : ['source','fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',

                    'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',

                    'insertunorderedlist', '|', 'table']

      });

   });

     });  

    

   LG.setFormDefaultBtn(f_cancel,f_save);

  

[d6]    </script>

  </body>

</html>

 

方式二:

 

 

 

 


 [d1]第一:

申明一個驗證用的變量

 [d2]第二:

在初始化函數中把表單綁定到驗證變量上

 [d3]第三:

如果添加失敗,返回頁面聚焦到標題輸入框

 [d4]第四:

save方法點擊後,先驗證

save

 [d5]第五:

頁面上運用驗證變量。限制輸入字符大小。

 [d6]定義tab下面的確定和取消按鈕。

需要再LG.js裏面看setFormDefaultBtn()方法是否寫了。否則按鈕也不會出來。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章