본문으로 바로가기
<script>
    // CKEDITOR 속성 편집
    // 리사이징 제한
    CKEDITOR.config.resize_enabled = false;
 
    // textarea의 ID 값
    CKEDITOR.replace('textarea');
 
    // onload
    $(function() {
        // input 태그 ID title에 onload 시 포커스
        $("#title").focus();
 
        // 취소 버튼 클릭 시 이전페이지로 이동
        $("#btn-cls").click(function() {
            history.back();
        });
 
        // edit-form을 ajaxForm plugin으로 submit
        $("#edit-form").form_helper({
            rules: {
                "title": {
                    "required"true,
                    "minlength"2
                }
            },
 
            messages: {
                "title": {
                    "required""제목을 입력하세요.",
                    "minlength""제목은 최소 2글자 이상 입력하세요."
                }
            },
            beforeSubmit: function(arr, form, options) {
                // 제출 전 에디터 내용을 변수에 저장
                var content = CKEDITOR.instances.textarea.getData();
                // 제출 전 에디터 내용 길이를 변수에 저장
                var content_len = CKEDITOR.instances.textarea.getData().length;
 
                // 내용이 없는 경우
                if (content == "") {
                    alert("알림""내용을 입력하세요."function() {
                        setTimeout(function() {
                        // 에디터 내용에 포커스 on
                        CKEDITOR.instances.textarea.focus();
                        }, 100);
                    }, "warning");
                    return false;
                }
 
                // 내용이 18글자 미만인 경우
                // 기본적으로 8글자를 가짐 빈문자열+<p></p> = 8글자
                if (content_len < 18) {
                    alert("알림""내용을 10자 이상 입력하세요."function() {
                        setTimeout(function() {
                            // 에디터 내용 초기화
                            CKEDITOR.instances.textarea.setData("");
                        }, 100);
                        // 에디터 내용에 포커스 on
                        CKEDITOR.instances.textarea.focus();
                    }, "warning");
                    return false;
                }
 
                // edit-form validate plugin 다시 실행
                return $("#edit-form").valid();
            },
            success: function(json) {
                alert("<font color='#05a'>Success</font>",
                    "<strong>수정되었습니다.</strong>",
                    function() {
                        location.href = "CommunityIndex.jsp";
                    }, "success");
            }
        });
    });
</script>



'Frontend > jQuery' 카테고리의 다른 글

CheckBox All Click & UnClick  (0) 2019.10.02
input 실시간 감지  (0) 2019.06.23
하루 전 날짜 계산  (0) 2019.02.20
클립보드에 복사하기  (0) 2019.02.20
html & remove 차이점  (0) 2019.02.11