글쓰기 폼 기본 글씨 지워지게
페이지 정보

본문
가장 안전하고 효과적인 위치는 write.skin.php 파일의 맨 마지막 부분입니다. 보통 HTML 코드가 끝나기 전인 </body> 태그나 </html> 태그 위에 넣어주시면 됩니다.
<script>
$(function() {
var content_id = 'wr_content';
var placeholder_text = '내용을 입력하세요.'; // 원하는 기본 글씨
// 에디터가 사용될 경우 (예: CKEditor)
if (typeof CKEDITOR !== 'undefined' && CKEDITOR.instances[content_id]) {
var editor = CKEDITOR.instances[content_id];
// 1. 초기 로드 시 Placeholder 설정
if (editor.getData().trim() === '') {
// Placeholder 텍스트를 흐린 색상으로 삽입
editor.setData('<p style="color:#aaa;">' + placeholder_text + '</p>');
}
// 2. 포커스를 얻을 때 (클릭 시) Placeholder 제거
editor.on('focus', function() {
// 현재 내용에 Placeholder 텍스트가 포함되어 있으면 제거
if (editor.getData().indexOf(placeholder_text) > -1) {
editor.setData('');
}
});
// 3. 포커스를 잃을 때 내용이 없으면 Placeholder 복구
editor.on('blur', function() {
if (editor.getData().trim() === '' || editor.getData() === '<p></p>') {
// 내용이 비어 있으면 다시 Placeholder 삽입
editor.setData('<p style="color:#aaa;">' + placeholder_text + '</p>');
}
});
} else {
// 에디터가 사용되지 않을 경우 (일반 textarea)
// HTML5 placeholder 속성 사용
$('#' + content_id).attr('placeholder', placeholder_text);
}
});
</script>
<script>
$(function() {
var content_id = 'wr_content';
var placeholder_text = '내용을 입력하세요.'; // 원하는 기본 글씨
// 에디터가 사용될 경우 (예: CKEditor)
if (typeof CKEDITOR !== 'undefined' && CKEDITOR.instances[content_id]) {
var editor = CKEDITOR.instances[content_id];
// 1. 초기 로드 시 Placeholder 설정
if (editor.getData().trim() === '') {
// Placeholder 텍스트를 흐린 색상으로 삽입
editor.setData('<p style="color:#aaa;">' + placeholder_text + '</p>');
}
// 2. 포커스를 얻을 때 (클릭 시) Placeholder 제거
editor.on('focus', function() {
// 현재 내용에 Placeholder 텍스트가 포함되어 있으면 제거
if (editor.getData().indexOf(placeholder_text) > -1) {
editor.setData('');
}
});
// 3. 포커스를 잃을 때 내용이 없으면 Placeholder 복구
editor.on('blur', function() {
if (editor.getData().trim() === '' || editor.getData() === '<p></p>') {
// 내용이 비어 있으면 다시 Placeholder 삽입
editor.setData('<p style="color:#aaa;">' + placeholder_text + '</p>');
}
});
} else {
// 에디터가 사용되지 않을 경우 (일반 textarea)
// HTML5 placeholder 속성 사용
$('#' + content_id).attr('placeholder', placeholder_text);
}
});
</script>
- 이전글테이블 추가 25.12.19
- 다음글게시판 제목폼지우기 25.12.13
댓글목록
등록된 댓글이 없습니다.

