jquery mobile 의 폼 검증

2601 단어 JQuery Mobile
jquery mobile 에서 특정한 폼 에 대한 검증 에 있어 서 jquery-vaidation 프레임 워 크 를 사용 할 수 있 습 니 다.
어차피 한 집 인 데 구체 적 인 예 는 다음 과 같다.
1)사용 하 는 js:
   jquery.validate.min.js
jquery.mobile-1.0a3.min.js
jquery.mobile-1.0a3.min.css
2)HTML 폼
 


<div data-role="page" id="login">
    
    <div data-role="header">
        <h1>Acme Corporation</h1>
    </div>
    
    <div data-role="content">
        
        <form id="frmLogin" class="validate">
            <div data-role="fieldcontain">
                <label for="email">[i]* [/i] Email: </label>
                <input type="text" id="email" name="email" 
                    class="required email" />
            </div>
            
            <div data-role="fieldcontain">
                <label for="password">[i]* [/i]Password: </label>
                <input type="password" id="password" name="password"
                    class="required" />
            </div>
            
            <div class="ui-body ui-body-b">
                <button class="btnLogin" type="submit" 
                    data-theme="a">Login</button>
            </div>
        </form>
        
    </div>
    
</div>

  class="required"를 더 하면 입력 해 야 할 항목 의 검증 을 완료 할 수 있 습 니 다.
3 검 증 된 JS 는 사실 간단 합 니 다.일반적인 jquery vaidate 와 같 습 니 다.
   $("#frmLogin").validate({
    submitHandler: function(form) {
        console.log("Call Login Action");
    }
});
   검증 에 성공 하면,진정한 논리 부분 을 실행 합 니 다.
4.jquery mobile 은 가로 와 세로 로 화면 을 전환 할 때 CSS 스타일 전환 도 제공 합 니 다.다음 과 같 습 니 다.
 


.portrait label.error, .landscape label.error {
    color: red;
    font-size: 16px;
    font-weight: normal;
    line-height: 1.4;
    margin-top: 0.5em;
    width: 100%;
    float: none;
}

.landscape label.error { display: inline-block; margin-left: 22%; }

.portrait label.error { margin-left: 0; display: block; }

em { color: red; font-weight: bold; padding-right: .25em; }

좋은 웹페이지 즐겨찾기