[JAVA SCRIPT]팁 모음

2012. 4. 25. 12:55NOTE/IT

매초마다 다른 이미지|글자 보여줌


<div id="aniBox">

      <!-- 이 공백기호는 반드시 필요, 생략시 에러! -->

</div>


<script>


   var message = new Array;


// ****************************************************************

    

// [사용자 변경이 가능한 옵션]


   var second = 2000; // 몇초마다 바꿀건지(1초는 1000)


       message[message.length] = '이곳에 입력1';  // 이미지는 '<img src="../images/your1.gif" />' 로 삽입

       message[message.length] = '이곳에 입력2';  // 테이블,이미지,가격표 '<table><tr><td> <img src="../images/" /> </td><tr><td>가격:000원</td></table>';

       message[message.length] = '이곳에 입력3';

       message[message.length] = '이곳에 입력4';


// ****************************************************************/

  


   var i=0;


   aniBox.innerHTML = message[i++];

   setInterval('aniBox.innerHTML = message[i++];i>=message.length?i=0:null;',second);


</script>


http://home.hanmir.com/~epjang/




숫자만 입력받기

<script>
  function checkPhone(e)
  {
    // 넷스케이프는 6,7 지원안됨, 최신 버전인 7.1에서야 비로소 지원됨
     
    var intCode = e.keyCode||e.which;

    if( !(intCode >= 48 && intCode <=57))
    {
        return false;
    }

    return true;
  }
</script>

<form>

<div onkeypress="return checkPhone(event)">
<input type="text" name="phone[]" /> - 
<input type="text" name="phone[]" /> - 
<input type="text" name="phone[]" />  
</div>

</form>

http://home.hanmir.com/~epjang/


주민번호 focus자동이동
<form>
<input type="text" name="jumin1" size="6" onkeyup="if(this.value.length==6){this.form.jumin2.focus();}" /> -  <input type="text" name="jumin2" size="7" /> 
</form>


프린트시 나타나는 문자
Mins 203.241.151.50http://www.minswa.com/zbxe/index.php?document_srl=566


<style media="screen">   <!-- 화면에만 보이도록 media="print"-->

  .myD{display:none;}

</style>


<div class="myD">Print Show</div> <!-- 프린트시 출력-->


일정시간후 창닫기

<script Laguage="Javascript"> 
function startTime(){ 
        var time= new Date(); 
        hours= time.getHours(); 
        mins= time.getMinutes(); 
        secs= time.getSeconds(); 
        closeTime=hours*3600+mins*60+secs; 
        closeTime+=5;  // This number is how long the window stays open 
        Timer(); 

function Timer(){ 
        var time= new Date(); 
        hours= time.getHours(); 
        mins= time.getMinutes(); 
        secs= time.getSeconds(); 
        curTime=hours*3600+mins*60+secs 
        if (curTime>=closeTime){ 
                self.close();} 
        else{ 
                window.setTimeout("Timer()",1000)} 
</script> 


<body onLoad="startTime();">. 

5초입니다
<input type=button name=simabuttonviewsource value="View Source" onClick='window.location="view-source:"+window.location.href'>




마우스가 올라가면 생겼다 벗어나면 없어지는 새창

<head>

<style>
A { color:#787878; text-decoration:none; }
A:Hover { color:#c0c0c0; text-decoration:none; }
</style>

<script language="javascript">
<!-- 
headstring = "<HTML><HEAD><TITLE>스크립트 예제</TITLE><HEAD>" 
bodystring = "<BODY bgcolor=#f3f3f3>" 
endstring = "</BODY></HTML>" 
iswin1 = 0; 
function me() { 
   if (iswin1==1) return; 
   win1 = open ("","","width=300,height=250"); 
   win1.document.open(); 
   win1.document.write (headstring); 
   win1.document.write (bodystring); 
   text1 ="<font color=#009999 size=5><b>마우스가 올라가면 새로 열리는 창<b> </font><p>"; 
   text1 += " Happy script <p>"; 
   text1 += " :: Mew :: <p>";
   text1 += " 응용이 쉽고 <p>";
   text1 += " 간편한 스크립트 입니다 <p>"; 
   text1 = "<center><font size=2 color=#0066cc>" + text1 + "</font></center>"; 
   win1.document.write (text1); 
   win1.document.write (endstring); 
   win1.document.close(); 
   iswin1 = 1; 
function me1() { 
   if (iswin1==0) return; 
   win1.close(); 
   iswin1 = 0; 
}  
//-->            
</script>
</head>
<body bgcolor="#f3f3f3" text="#009999">
<p align=center>
<font style="font-family:Cursive;font-size:14pt;color:#009999">

<b>예제</b>
</font>
<p align=center>
<font face="굴림" size="2">
마우스를 링크 영역에 가져가면
</font>
<p align=center>
<font face="굴림" size="2">
새 브라우저가 열리는 예제
</font>
<p align="center">
<font face="굴림" size="2">
<a href="  " onmouseover="me()" onmouseout="me1()" onclick="me1()">
마우스 커서를 여기에 !
</a>
</font>
</body><input type=button name=simabuttonviewsource value="View Source" onClick='window.location="view-source:"+window.location.href'>



아날로그 시계
<SCRIPT LANGUAGE="JavaScript">  

<!-- Begin  
pX = 100;  
pY = 100;  
obs = new Array(13);  
function ob() {  
for (i = 0; i < 13; i++) {  
if (document.all) obs[i] = new Array (eval('ob'+i).style,-100,-100);  
else obs[i] = new Array (eval('document.ob'+i),-100,-100);  
   }  
}  
function cl(a, b, c) {  
if (document.all) {  
if (a != 0) b += -1;  
eval('c'+a+'.style.pixelTop='+(pY+(c)));  
eval('c'+a+'.style.pixelLeft='+(pX+(b)));  
}  
else {  
if (a != 0) b += 10;  
eval('document.c'+a+'.top='+(pY+(c)));  
eval('document.c'+a+'.left='+(pX+(b)));  
   }  
}  
function runClock() {  
for (i = 0; i < 13; i++) {  
obs[i][0].left=obs[i][1]+pX;  
obs[i][0].top=obs[i][2]+pY;  
   }  
}  
var lastsec;  
function timer() {  
time = new Date ();  
sec = time.getSeconds();  
if (sec != lastsec) {  
lastsec = sec;  
sec = Math.PI * sec / 30;  
min = Math.PI * time.getMinutes() / 30;  
hr = Math.PI * time.getHours() / 6 + Math.PI * parseInt(time.getMinutes()) / 360;  
for (i = 1; i < 6; i++) {  
obs[i][1] = Math.sin(sec) * (44 - (i-1) * 11) - 16;  
if (document.layers)obs[i][1] += 10;  
obs[i][2] = -Math.cos(sec) * (44 - (i-1) * 11) - 27;  
}  
for (i = 6;i < 10; i++) {  
obs[i][1] = Math.sin(min) * (40 - (i-6) * 10) - 16;  
if (document.layers)obs[i][1] += 10;  
obs[i][2] = -Math.cos(min) * (40 - (i-6) * 10) - 27;  
}  
for (i = 10; i < 13; i++) {  
obs[i][1] = Math.sin(hr) * (37 - (i-10) * 11) - 16;  
if (document.layers)obs[i][1] += 10;  
obs[i][2] = -Math.cos(hr) * (37 - (i-10) * 11) - 27;  
      }  
   }  
}  
function setNum() {  
cl (0, -67, -65);  
cl (1, 10, -51);  
cl (2, 28, -33);  
cl (3, 35, -8);  
cl (4, 28, 17);  
cl (5, 10, 35);  
cl (6, -15, 42);  
cl (7, -40, 35);  
cl (8, -58, 17);  
cl (9, -65, -8);  
cl (10, -58, -33);  
cl (11, -40, -51);  
cl (12, -16, -56);  
}  
function startClock() {  
ob();  
setNum();  
setInterval('timer()', 100);  
setInterval('runClock()', 100);  
}  
// End -->  
</script>  
<style>  
..num {color:white;width:30px;text-align:center; }  
</style>  
</HEAD>  

<body bgcolor=#000000 onLoad="javascript:startClock();">  

<div id="c0" style="position:absolute;left:36;top:36; z-index:2;">  
<table>  
<tr>  
<td bgcolor=000000 width=120 height=120>  
</td>  
</tr>  
</table>  
</div>  
<div id="c1" class="num" style="position:absolute;left:20;top:-20; z-index:5;font-size:11px;"><b>1</b></div>  
<div id="c2" class="num" style="position:absolute;left:20;top:-20; z-index:5;font-size:11px;"><b>2</b></div>  
<div id="c3" class="num" style="position:absolute;left:20;top:-20; z-index:5;font-size:11px;"><b>3</b></div>  
<div id="c4" class="num" style="position:absolute;left:20;top:-20; z-index:5;font-size:11px;"><b>4</b></div>  
<div id="c5" class="num" style="position:absolute;left:20;top:-20; z-index:5;font-size:11px;"><b>5</b></div>  
<div id="c6" class="num" style="position:absolute;left:20;top:-20; z-index:5;font-size:11px;"><b>6</b></div>  
<div id="c7" class="num" style="position:absolute;left:20;top:-20; z-index:5;font-size:11px;"><b>7</b></div>  
<div id="c8" class="num" style="position:absolute;left:20;top:-20; z-index:5;font-size:11px;"><b>8</b></div>  
<div id="c9" class="num" style="position:absolute;left:20;top:-20; z-index:5;font-size:11px;"><b>9</b></div>  
<div id="c10" class="num" style="position:absolute;left:20;top:-20; z-index:5;font-size:11px;"><b>10</b></div>  
<div id="c11" class="num" style="position:absolute;left:20;top:-20; z-index:5;font-size:11px;"><b>11</b></div>  
<div id="c12" class="num" style="position:absolute;left:20;top:-20; z-index:5;font-size:11px;"><b>12</b></div>  

<div id="ob0" class="num" style="position:absolute;left:-20;top:-20;z-index:1">  
</div>  
<div id="ob1" class="num" style="position:absolute;left:-20;top:-20;z-index:8">  
<font size="+3" color="#0000ff"><b>.</b></font></div>  
<div id="ob2" class="num" style="position:absolute;left:-20;top:-20;z-index:8">  
<font size="+3" color="#0000ff"><b>.</b></font></div>  
<div id="ob3" class="num" style="position:absolute;left:-20;top:-20;z-index:8">  
<font size="+3" color="#0000ff"><b>.</b></font></div>  
<div id="ob4" class="num" style="position:absolute;left:-20;top:-20;z-index:8">  
<font size="+3" color="#0000ff"><b>.</b></font></div>  
<div id="ob5" class="num" style="position:absolute;left:-20;top:-20;z-index:8">  
<font size="+3" color="#0000ff"><b>.</b></font></div>  
<div id="ob6" class="num" style="position:absolute;left:-20;top:-20;z-index:7">  
<font size="+3" color="#00ffff"><b>.</b></font></div>  
<div id="ob7" class="num" style="position:absolute;left:-20;top:-20;z-index:7">  
<font size="+3" color="#00ffff"><b>.</b></font></div>  
<div id="ob8" class="num" style="position:absolute;left:-20;top:-20;z-index:7">  
<font size="+3" color="#00ffff"><b>.</b></font></div>  
<div id="ob9" class="num" style="position:absolute;left:-20;top:-20;z-index:7">  
<font size="+3" color="#00ffff"><b>.</b></font></div>  
<div id="ob10" class="num" style="position:absolute;left:-20;top:-20;z-index:6">  
<font size="+3" color="#ffff00"><b>.</b></font></div>  
<div id="ob11" class="num" style="position:absolute;left:-20;top:-20;z-index:6">  
<font size="+3" color="#ffff00"><b>.</b></font></div>  
<div id="ob12" class="num" style="position:absolute;left:-20;top:-20;z-index:6">  
<font size="+3" color="#ffff00"><b>.</b></font></div>  
<!--start sima--><center><input type="button" value="View Source" onClick='window.location="view-source:"+window.location.href'><!--end sima-->



초시계..


<SCRIPT LANGUAGE="JavaScript"> 

<!-- 
startday = new Date(); 
clockStart = startday.getTime(); 

function initStopwatch() { 
var myTime = new Date(); 
return((myTime.getTime() - clockStart)/1000); 


function getSecs() { 
var tSecs = Math.round(initStopwatch()); 
var iSecs = tSecs % 60; 
var iMins = Math.round((tSecs-30)/60);   
var sSecs ="" + ((iSecs > 9) ? iSecs : "0" + iSecs); 
var sMins ="" + ((iMins > 9) ? iMins : "0" + iMins); 
document.forms[0].timespent.value = sMins+":"+sSecs; 
window.setTimeout('getSecs()',1000); 

// End --> 
</script> 

</HEAD> 

<BODY onLoad="window.setTimeout('getSecs()',1)"> 
<form name=test>
<input type=text name=timespent>
</form><!--start sima--><center><input type="button" value="View Source" onClick='window.location="view-source:"+window.location.href'><!--end sima-->



우측하단 아날로그시계

<script language="javascript">
<!--
///////////////////////////////////////////// 
//         :*: Happyscript :*:             // 
// 소스 : http://www.happyscript.net       // 
// 편집 and 소스 설명 : Magic              // 
// E-mail : flyingmagic@hanmail.net        // 
///////////////////////////////////////////// 

fCol='000000'; // 숫자 색
sCol='ff0000'; // 초바늘 색
mCol='000000'; // 분바늘 색
hCol='000000'; // 시바늘 색

// 자신있는 사람만 손댈것
H='....';
H=H.split('');
M='.....';
M=M.split('');
S='......';
S=S.split('');

Ypos=0;
Xpos=0;
Ybase=8;
Xbase=8;
dots=12;
ns=(document.layers)?1:0;
if (ns){
dgts='1 2 3 4 5 6 7 8 9 10 11 12';
dgts=dgts.split(' ')
for (i=0; i < dots; i++){

document.write('<layer name=nsDigits'+i+' top=0 left=0 height=30 width=30><center><font face=Arial,Verdana size=1 color='+fCol+'>'+dgts[i]+'</font></center></layer>');
}
for (i=0; i < M.length; i++){
document.write('<layer name=ny'+i+' top=0 left=0 bgcolor='+mCol+' clip="0,0,2,2"></layer>');
}
for (i=0; i < H.length; i++){
document.write('<layer name=nz'+i+' top=0 left=0 bgcolor='+hCol+' clip="0,0,2,2"></layer>');
}
for (i=0; i < S.length; i++){
document.write('<layer name=nx'+i+' top=0 left=0 bgcolor='+sCol+' clip="0,0,2,2"></layer>');
}
}
else{
document.write('<div style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=1; i < dots+1; i++){
document.write('<div id="ieDigits" style="position:absolute;top:0px;left:0px;width:30px;height:30px;font-family:Arial,Verdana;font-size:10px;color:'+fCol+';text-align:center;padding-top:10px">'+i+'</div>');
}
document.write('</div></div>')
document.write('<div style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < M.length; i++){
document.write('<div id=y style="position:absolute;width:2px;height:2px;font-size:2px;background:'+mCol+'"></div>');
}
document.write('</div></div>')
document.write('</div></div>')
document.write('<div style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < H.length; i++){
document.write('<div id=z style="position:absolute;width:2px;height:2px;font-size:2px;background:'+hCol+'"></div>');
}
document.write('</div></div>')
document.write('<div style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < S.length; i++){
document.write('<div id=x style="position:absolute;width:2px;height:2px;font-size:2px;background:'+sCol+'"></div>');
}
document.write('</div></div>')
}

function clock(){
time = new Date ();
secs = time.getSeconds();
sec = -1.57 + Math.PI * secs/30;
mins = time.getMinutes();
min = -1.57 + Math.PI * mins/30;
hr = time.getHours();
hrs = -1.57 + Math.PI * hr/6 + Math.PI*parseInt(time.getMinutes())/360;
if (ns){
Ypos=window.pageYOffset+window.innerHeight-60;
Xpos=window.pageXOffset+window.innerWidth-80;
}
else{
Ypos=document.body.scrollTop+window.document.body.clientHeight-60;
Xpos=document.body.scrollLeft+window.document.body.clientWidth-60;
}
if (ns){
for (i=0; i < dots; ++i){
document.layers["nsDigits"+i].top=Ypos-5+40*Math.sin(-0.49+dots+i/1.9);
document.layers["nsDigits"+i].left=Xpos-15+40*Math.cos(-0.49+dots+i/1.9);
}
for (i=0; i < S.length; i++){
document.layers["nx"+i].top=Ypos+i*Ybase*Math.sin(sec);
document.layers["nx"+i].left=Xpos+i*Xbase*Math.cos(sec);
}
for (i=0; i < M.length; i++){
document.layers["ny"+i].top=Ypos+i*Ybase*Math.sin(min);
document.layers["ny"+i].left=Xpos+i*Xbase*Math.cos(min);
}
for (i=0; i < H.length; i++){
document.layers["nz"+i].top=Ypos+i*Ybase*Math.sin(hrs);
document.layers["nz"+i].left=Xpos+i*Xbase*Math.cos(hrs);
}
}
else{
for (i=0; i < dots; ++i){
ieDigits[i].style.pixelTop=Ypos-15+40*Math.sin(-0.49+dots+i/1.9);
ieDigits[i].style.pixelLeft=Xpos-14+40*Math.cos(-0.49+dots+i/1.9);
}
for (i=0; i < S.length; i++){
x[i].style.pixelTop =Ypos+i*Ybase*Math.sin(sec);
x[i].style.pixelLeft=Xpos+i*Xbase*Math.cos(sec);
}
for (i=0; i < M.length; i++){
y[i].style.pixelTop =Ypos+i*Ybase*Math.sin(min);
y[i].style.pixelLeft=Xpos+i*Xbase*Math.cos(min);
}
for (i=0; i < H.length; i++){
z[i].style.pixelTop =Ypos+i*Ybase*Math.sin(hrs);
z[i].style.pixelLeft=Xpos+i*Xbase*Math.cos(hrs);
}
}
setTimeout('clock()',50);
}
if (document.layers || document.all) window.onload=clock;
//-->
</script>
<br><bR><bR><bR><br><br><bR><bR><bR><br><br><bR><bR><bR><br>
<br><bR><bR><bR><br><br><bR><bR><bR><br><br><bR><bR><bR><br>
<br><bR><bR><bR><br><br><bR><bR><bR><br><br><bR><bR><bR><br>
<br><bR><bR><bR><br><br><bR><bR><bR><br><br><bR><bR><bR><br>
<br><bR><bR><bR><br><br><bR><bR><bR><br><br><bR><bR><bR><br>
<br><bR><bR><bR><br><br><bR><bR><bR><br><br><bR><bR><bR><br>
<!--start sima--><center><input type="button" value="View Source" onClick='window.location="view-source:"+window.location.href'><!--end sima-->




전체 이미지 갯수와 현재 이미지 번호가 보여지는 이미지 슬라이드 소스

<!-- 페이지 로딩시 로드되는 이미지의 경로 - name부분은 지우면 안됨.. //-->
<img src="http://user.chollian.net/~yookmjl/icsUpload/photopds/YellowstoneLakeSunset3-1024.jpg" width="600" height="370" name="photoslider">

<script language="JavaScript">
<!--
var photos=new Array()
var which=0

// 이미지 경로부분
// 추가시엔 photos[X]="URL"를 원하는 이미지의 갯수만큼 복사하여
// X부분에 0부터 차례대로 숫자를 적어주며 URL부분에 각 부분의 이미지의 경로를 적으면 됨
photos[0]="http://user.chollian.net/~yookmjl/icsUpload/photopds/YellowstoneLakeSunset3-1024.jpg"
photos[1]="http://user.chollian.net/~yookmjl/icsUpload/photopds/YellowstoneLakeSunset2b-1024.jpg"
photos[2]="http://user.chollian.net/~yookmjl/icsUpload/photopds/cyuohlawn3.jpg"
photos[3]="http://user.chollian.net/~yookmjl/icsUpload/photopds/AlpenVillageWildflowers3-1024.jpg"
photos[4]="http://user.chollian.net/~yookmjl/icsUpload/photopds/AlpenVillage-1024.jpg"
photos[5]="http://user.chollian.net/~yookmjl/icsUpload/photopds/AlpsScene3-1024.jpg"
photos[6]="../../../kjy/javalink/h1.gif"
photos[7]="../../../kjy/javalink/h2.gif"
photos[8]="../../../kjy/javalink/h3.gif"

function backward(){
if (which>0){
window.status=''
which--
document.all._Ath_Img_X.innerHTML = which+1;
document.all._Ath_Img_N.innerHTML = photos.length;
document.images.photoslider.src=photos[which]
}
}

function forward(){
if (which<photos.length-1){
which++
document.all._Ath_Img_X.innerHTML = which+1;
document.all._Ath_Img_N.innerHTML = photos.length;
document.images.photoslider.src=photos[which]
}
else window.status='이미지가 없습니다.' // 이미지가 끝났을시 상태바 메세지
}
//-->
</script>

<br>


<!--
보여지는 이미지의 번호 / 전체 이미지의 갯수
전체 이미지의 갯수는 다음 이미지로 넘기면 자동으로 전체 이미지 갯수가 표시됨
//-->
<SPAN id="_Ath_Img_X">1</SPAN>/<SPAN id="_Ath_Img_N">9</SPAN>

<!-- 이미지를 처음으로 이동시키는 부분 //-->
<input type="button" value="처음으로" onClick="which=1;backward();return false">
<!-- 이미지를 1단계 뒤로 이동시킴 //-->
<input type="button" value="뒤로" onClick="backward();">
<!-- 이미지를 1단계 앞으로 이동시킴 //-->
<input type="button" value="앞으로" onClick="forward();">
<!--
이미지를 마지막으로 이동시키는 부분
예를들어 전체 이미지의 갯수가 10개라면 위 이미지 경로부분에는 0,1,2,3,4,5,6,7,8,9 이렇게 구성된다
여기서 전체 이미지의 갯수에서 1을 뺀값 그러니 9-1이니 8을 아래 which의 값으로 적으면 됨
//-->
<input type="button" value="마지막으로" onClick="which=7;forward();return false"><input type=button name=simabuttonviewsource value="View Source" onClick='window.location="view-source:"+window.location.href'>