웹마스터 팁
page_full_width" class="col-xs-12" |cond="$__Context->page_full_width">
행복한고니님의 체크박스를 이미지로 사용하기를 보고... 체크박스옆에 텍스트 부치기
2004.10.29 23:49
처음 고니님의 함수들 보고 정말 놀랬더랬습니다.
이런것도 있구나하구요..^^;;
msdn 들가보니까 있긴있더라구요..-ㅁ-;
그래서 함따라해봤습니다.
고니님이 하신건 체크박스를 이미지로 교체해서 표현하는거구요
저는 라이오 박스나 체크박스를 그냥 쓰되 바로엽에 글자를 넣어서 글자를 클릭해도 선택이 되게한겁니다.
아직 이런식으로 해본 경험이 없던 터라..많이 부족할겁니다.
사용방법은
<input type="radio" name="a" text="여기다 표시할 문자를 넣습니다.">
<input type="checkbox" name="b" text="여기다 표시할 문자를 넣습니다.">
스크립트는 가급적 <head>와 ~ </head> 사이에 넣으시구요
<body onload="LabelChoice()"> 하시거나
<input 태그가 마지막으로 끝나는 다음에
<script> LabelChoice() </script>
를 넣어주세요.
예제 ) http://maxpond.netcci.net/etc/LabelChoice.html
<script Language="JavaScript" type="text/JavaScript">
<!--
/* 라디오 버튼이나 체크박스를 찾아 변환 */
function LabelChoice(){
var choice, span;
inputs = document.getElementsByTagName( "INPUT" ); // 현재 문서의 엘리먼트중 input 태그만 가져오기
for( i=0; i<inputs.length; i++ ){ // 가져온 인풋태그를 모두 확인
if( inputs[i].type != "radio" && inputs[i].type != "checkbox" ) continue; // 뭘 확인? 라디오 버튼인지 체크버튼인지
if( inputs[i].getAttribute("text") == null ) continue; // text라는 어트리뷰트가 있는지
LabelChoice.choiceBox[LabelChoice.choiceBox.length] = choice = inputs[i]; // 이벤트 처리를 위한 객체를 배열로 넣어둠
LabelChoice.spans[LabelChoice.spans.length] = span = document.createElement( "SPAN" ); // 라벨을 위한 span 태그를 하나 만듬
// span 태그의 글자를 text 어트리뷰트로 정의된 문자열로 채움
span.innerHTML = choice.getAttribute("text");
span.style.cursor = "hand"; // span 태그 커서를 손모양으로
if( choice.checked ) // 기본값 확인
span.style.fontWeight = "bold"; // 체크됬으면 볼드체
choice.oldOnClick = choice.getAttribute( "onclick" ); // 이미 지정된 onclick 이벤트 저장
// 새 onclick 이벤트 등록
span.onclick = new Function( "LabelChoice.onclick('"+(LabelChoice.choiceBox.length-1)+"', 1);" );
choice.onclick = new Function( "LabelChoice.onclick('"+(LabelChoice.choiceBox.length-1)+"', 0);" );
// 체크박스 또는 라디오 버튼 옆에 span 태그를 넣음
choice.insertAdjacentElement( "afterEnd", span );
}
}
/* span 이나 라디오 버튼 클릭시 */
LabelChoice.onclick = function( idx, flag ){
if( flag ){ // span 태그의 onclick 이벤트 발생시
if( LabelChoice.choiceBox[idx].type == "checkbox" ) // 변환된 객체가 체크박스라면
LabelChoice.choiceBox[idx].checked = !LabelChoice.choiceBox[idx].checked; // 반전체크
else
LabelChoice.choiceBox[idx].checked = true; // 라디오 버튼이면 항상 체크
LabelChoice.choiceBox[idx].fireEvent( "onclick" ); // 라디오 또는 체크박스를 대상으로 onclick 이벤트 발생
return;
}
choice = LabelChoice.choiceBox[idx];
choiceSpan = LabelChoice.spans[idx];
choice.oldOnClick(); // 기본으로 등록된 onclick 이벤트 먼저 실행
if( choice.type == "radio" ){ // 라디오 버튼이면
for( i=0; i<LabelChoice.choiceBox.length; i++ ){
if( choice.name != LabelChoice.choiceBox[i].name ) continue; // 이벤트를 발생시킨 객체와 다른 그룹의 라디오 버튼이면 쌩~
LabelChoice.spans[i].style.fontWeight=""; // 아니면 span 태그의 글자체를 default 값으로
}
}
choice.checked = choice.checked;
if( choice.checked )
choiceSpan.style.fontWeight = "bold"; //볼드체로
else
choiceSpan.style.fontWeight = ""; // default 로
}
LabelChoice.choiceBox = [];
LabelChoice.spans = [];
//-->
</script>
<style>
body, span, input { font-size:12px }
</style>
<body onload="LabelChoice()">
<input type="radio" name="A" text="A 그룹 선택하기1"><br>
<input type="radio" name="A" text="A 그룹 선택하기2" checked><br>
<input type="radio" name="A" text="A 그룹 선택하기3"><br>
<p>
<input type="radio" name="B" text="B 그룹 선택하기1"><br>
<input type="radio" name="B" text="B 그룹 선택하기2"><br>
<input type="radio" name="B" text="B 그룹 선택하기3"><br>
<p>
<input type="checkbox" name="checkbox[]" text="이번엔 체크박스1"><br>
<input type="checkbox" name="checkbox[]" text="이번엔 체크박스2"><br>
<input type="checkbox" name="checkbox[]" text="이번엔 체크박스3"><br>
이런것도 있구나하구요..^^;;
msdn 들가보니까 있긴있더라구요..-ㅁ-;
그래서 함따라해봤습니다.
고니님이 하신건 체크박스를 이미지로 교체해서 표현하는거구요
저는 라이오 박스나 체크박스를 그냥 쓰되 바로엽에 글자를 넣어서 글자를 클릭해도 선택이 되게한겁니다.
아직 이런식으로 해본 경험이 없던 터라..많이 부족할겁니다.
사용방법은
<input type="radio" name="a" text="여기다 표시할 문자를 넣습니다.">
<input type="checkbox" name="b" text="여기다 표시할 문자를 넣습니다.">
스크립트는 가급적 <head>와 ~ </head> 사이에 넣으시구요
<body onload="LabelChoice()"> 하시거나
<input 태그가 마지막으로 끝나는 다음에
<script> LabelChoice() </script>
를 넣어주세요.
예제 ) http://maxpond.netcci.net/etc/LabelChoice.html
<script Language="JavaScript" type="text/JavaScript">
<!--
/* 라디오 버튼이나 체크박스를 찾아 변환 */
function LabelChoice(){
var choice, span;
inputs = document.getElementsByTagName( "INPUT" ); // 현재 문서의 엘리먼트중 input 태그만 가져오기
for( i=0; i<inputs.length; i++ ){ // 가져온 인풋태그를 모두 확인
if( inputs[i].type != "radio" && inputs[i].type != "checkbox" ) continue; // 뭘 확인? 라디오 버튼인지 체크버튼인지
if( inputs[i].getAttribute("text") == null ) continue; // text라는 어트리뷰트가 있는지
LabelChoice.choiceBox[LabelChoice.choiceBox.length] = choice = inputs[i]; // 이벤트 처리를 위한 객체를 배열로 넣어둠
LabelChoice.spans[LabelChoice.spans.length] = span = document.createElement( "SPAN" ); // 라벨을 위한 span 태그를 하나 만듬
// span 태그의 글자를 text 어트리뷰트로 정의된 문자열로 채움
span.innerHTML = choice.getAttribute("text");
span.style.cursor = "hand"; // span 태그 커서를 손모양으로
if( choice.checked ) // 기본값 확인
span.style.fontWeight = "bold"; // 체크됬으면 볼드체
choice.oldOnClick = choice.getAttribute( "onclick" ); // 이미 지정된 onclick 이벤트 저장
// 새 onclick 이벤트 등록
span.onclick = new Function( "LabelChoice.onclick('"+(LabelChoice.choiceBox.length-1)+"', 1);" );
choice.onclick = new Function( "LabelChoice.onclick('"+(LabelChoice.choiceBox.length-1)+"', 0);" );
// 체크박스 또는 라디오 버튼 옆에 span 태그를 넣음
choice.insertAdjacentElement( "afterEnd", span );
}
}
/* span 이나 라디오 버튼 클릭시 */
LabelChoice.onclick = function( idx, flag ){
if( flag ){ // span 태그의 onclick 이벤트 발생시
if( LabelChoice.choiceBox[idx].type == "checkbox" ) // 변환된 객체가 체크박스라면
LabelChoice.choiceBox[idx].checked = !LabelChoice.choiceBox[idx].checked; // 반전체크
else
LabelChoice.choiceBox[idx].checked = true; // 라디오 버튼이면 항상 체크
LabelChoice.choiceBox[idx].fireEvent( "onclick" ); // 라디오 또는 체크박스를 대상으로 onclick 이벤트 발생
return;
}
choice = LabelChoice.choiceBox[idx];
choiceSpan = LabelChoice.spans[idx];
choice.oldOnClick(); // 기본으로 등록된 onclick 이벤트 먼저 실행
if( choice.type == "radio" ){ // 라디오 버튼이면
for( i=0; i<LabelChoice.choiceBox.length; i++ ){
if( choice.name != LabelChoice.choiceBox[i].name ) continue; // 이벤트를 발생시킨 객체와 다른 그룹의 라디오 버튼이면 쌩~
LabelChoice.spans[i].style.fontWeight=""; // 아니면 span 태그의 글자체를 default 값으로
}
}
choice.checked = choice.checked;
if( choice.checked )
choiceSpan.style.fontWeight = "bold"; //볼드체로
else
choiceSpan.style.fontWeight = ""; // default 로
}
LabelChoice.choiceBox = [];
LabelChoice.spans = [];
//-->
</script>
<style>
body, span, input { font-size:12px }
</style>
<body onload="LabelChoice()">
<input type="radio" name="A" text="A 그룹 선택하기1"><br>
<input type="radio" name="A" text="A 그룹 선택하기2" checked><br>
<input type="radio" name="A" text="A 그룹 선택하기3"><br>
<p>
<input type="radio" name="B" text="B 그룹 선택하기1"><br>
<input type="radio" name="B" text="B 그룹 선택하기2"><br>
<input type="radio" name="B" text="B 그룹 선택하기3"><br>
<p>
<input type="checkbox" name="checkbox[]" text="이번엔 체크박스1"><br>
<input type="checkbox" name="checkbox[]" text="이번엔 체크박스2"><br>
<input type="checkbox" name="checkbox[]" text="이번엔 체크박스3"><br>
댓글 2
-
beMax
2005.04.02 09:13
-
잠수부
2005.01.14 19:24
헛참.. 죄송해서..
<input type="radio" id="test"><label for="test">테스트</label>
제목 | 글쓴이 | 날짜 |
---|---|---|
[PHP 동영상강의] 49. 만년달력 제작해보기 [1] | 서기 | 2007.08.08 |
[PHP 동영상강의] 50. 자바스크립트로 풀다운 메뉴제작 [2] | 서기 | 2007.08.08 |
[PHP 동영상강의] 51. db와 연동된 다중 셀렉트 제작하기 [7] | 서기 | 2007.08.08 |
[zbXE 동영상강좌] 1. zbXE 설치하기 [2] | 서기 | 2007.08.16 |
[zbXE 동영상강좌] 2. 포토샵에서 레이아웃 만들기 [12] | 서기 | 2007.08.16 |
[zbXE 동영상강좌] 3. 레이아웃 완성하기 [13] | 서기 | 2007.08.16 |
[PDF 제작하기 동영상강좌] 1. 기본환경 설정 [1] | 서기 | 2007.08.18 |
[PDF 제작하기 동영상강좌] 2. Hello PDF | 서기 | 2007.08.18 |
[PDF 제작하기 동영상강좌] 3. 기존의 PDF파일 불러오기 [2] | 서기 | 2007.08.18 |
간단한 칠판 모양 게시판
[9]
![]() | SoukoZ | 2007.08.19 |
포인트부여시 ...회원로그인 [2] | 구본순 | 2007.08.28 |
관리자모드 - 관리자그룹만 모든 회원리스트보기 [2] | 이지혜609 | 2007.10.23 |
php에서 exif소스이용하기 [5] | 최만순279 | 2007.11.18 |
웹 계정에서 지워지지 않는 폴더 및 파일 삭제하는 방법 [3] | Rising.kr | 2008.01.24 |
OGIT STUDY 1 | OGIT | 2008.02.01 |
OGIT STUDY 2 [1] | OGIT | 2008.02.01 |
OGIT STUDY 3 [1] | OGIT | 2008.02.01 |
웹페이지 미리보기 snapshot 활용하기 [2] | 유창화 | 2008.02.15 |
FLV 사이트 다운로더 소스
![]() | fallstoofast | 2008.03.07 |
해시로부터 주민등록번호 복호화 [2] | fallstoofast | 2008.03.12 |
>>ㅑ~
이런게 있었다니..;;-_-;;
코멘트에는 추천없나..-ㅁ-;;;;;;;;;;;;;;;;
잠수부님 감사요..^^;;