예제소스 - http://bboong100.cafe24.com/0915/calc.html

 

현재 까지 가능한 기능

텍스트창 오른쪽 정렬

엔터키로 연산

소수점 값 입력

위에 텍스트에 먼저 입력한 숫자와 연산자를 표시하고 연산 결과는 아래창에 출력되는 기능

연산자, 0, 소수점(.) 중복 입력시 처리 문제

'C' 버튼을 눌렀을 때 위 텍스트창도 초기화

연산 결과 나오고 다시 연산자 버튼을 눌렀을 때 위 텍스트 창에 기존 수식이 계속 출력되던 문제 해결

처음 숫자 입력 하고 연산자 누르고 다른 연산자 눌렀을 때 나중에 누른 연산자로 대체되어야 하는 문제

백스페이스 눌렀을 때 생기는 오류들 예외처리!

추가할 기능

. 을 두 번 이상 눌렀을 때 생기는 오류들 ...

Posted by 공돌공돌
,

 

예제소스 - http://bboong100.cafe24.com/0911/test02.html

 

test02.html  (부모창)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
<script type="text/javascript">
function popup()
{
    var flag;
    //http://naver.com
    var url = "popup1.html";
    var popupname = "popupwin";

    flag = "left=200, ";
    flag += "top=200, ";
    flag += "width=400, ";
    flag += "height=250";
    window.open(url, popupname, flag);
}

function popuptest1(name, code)
{
    var testtable = document.getElementById("popuptest");
    var tr = document.createElement("tr");
    tr.setAttribute("height", "30");
    if (name == "" || code == "") {
        alert('문자 입력하시오');
        return;
    }

    var td1 = document.createElement("td");
    td1.setAttribute("width", "100");

    var td2 = document.createElement("td");
    td2.setAttribute("width", "200");

    tr.appendChild(td1);
    tr.appendChild(td2);

    td1.innerText = name;
    td2.innerText = code;

    if (testtable.firstChild.lastChild.childNodes.length == 1)
        testtable.firstChild.removeChild(testtable.firstChild.lastChild);

    testtable.firstChild.appendChild(tr);
}
 </script>
 </HEAD>
 <BODY>
 
    팝업테스트  <input type="button" value="popup" onclick="popup()"> <p><p>
    <table id="popuptest" border="2">
        <tr>
            <th width="100">name</th>
            <th width="100">code</th>
        </tr>
    </table>
 </BODY>
</HTML>

 


test02_1.html   (자식창_팝업창)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
<script type="text/javascript">
        function add2()
        {
            var name = document.ex.name.value;
            var code = document.ex.code.value;
            opener.popuptest1(name, code);
            self.close()
        }

        function reset()
        {
            document.all.name.value="";
            document.all.code.value="";
        }
 </script>
 </HEAD>
 <BODY>
 
<form name='ex'>
 Name : <input type="text" size="10" name="name" id="name" ><br>
 Code : <input type="text" size="10" name="code" id="code" ><br>

 <input type="button" value="추가" onclick="add2()">
 <input type="button" value="초기화" onClick="reset();">

</form>
 </BODY>
</HTML>

'개발개발 > 자바스크립트' 카테고리의 다른 글

계산기 진행상황 (0915)  (1) 2012.09.15
문서객체  (0) 2012.09.11
0906 자바스크립트 계산기  (0) 2012.09.06
계산기 문제점  (0) 2012.09.06
0905 자바스크립트 계산기  (0) 2012.09.05
Posted by 공돌공돌
,

 

예제확인 - http://bboong100.cafe24.com/0911/test01.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
<script type="text/javascript">
  function teTable()
{
    // var test = $('test');
    var testtable = document.getElementById("test");
    // table 개체 가져와서 testtable에 저장
    var tr = document.createElement("tr");
    // tr 개체 가져와서 testtr에 저장
    tr.setAttribute("height", "30");
    if (document.all.subject.value == "" || document.all.content.value == "") {
        alert('문자 입력하시오');
        return;
    }

    var td1 = document.createElement("td");
    td1.setAttribute("width", "100");

    var td2 = document.createElement("td");
    td2.setAttribute("width", "200");

    tr.appendChild(td1);
    tr.appendChild(td2);

    td2.innerText = document.all.content.value;
    td1.innerText = document.all.subject.value;

    if (testtable.firstChild.lastChild.childNodes.length == 1)
        testtable.firstChild.removeChild(testtable.firstChild.lastChild);

    testtable.firstChild.appendChild(tr);

    document.all.subject.value = '';
    document.all.content.value = '';
}
 </script>

 </HEAD>

 <BODY>
 <table id="test" border="2">
        <tr>
            <th width="100">subject</th>
            <th width="100">content</th>
        </tr>
    </table>
    1 : <input type="text" size="10" name="subject"> 2 : <input type="text" size="10" name="content">
        <input type="button" value="추가" onclick="teTable()">
 
 </BODY>
</HTML>

Posted by 공돌공돌
,

 

http://bboong100.cafe24.com/0906/calc.html

현재 까지 가능한 기능

텍스트창 오른쪽 정렬

엔터키로 연산

소수점 값 입력

위에 텍스트에 먼저 입력한 숫자와 연산자를 표시하고 연산 결과는 아래창에 출력되는 기능

연산자, 0, 소수점(.) 중복 입력시 처리 문제

'C' 버튼을 눌렀을 때 위 텍스트창도 초기화

연산 결과 나오고 다시 연산자 버튼을 눌렀을 때 위 텍스트 창에 기존 수식이 계속 출력되던 문제 해결

처음 숫자 입력 하고 연산자 누르고 다른 연산자 눌렀을 때 나중에 누른 연산자로 대체되어야 하는 문제

추가할 기능

백스페이스 눌렀을 때 생기는 오류들 ...

.  을 두 번 이상 눌렀을 때 생기는 오류들 ...

Posted by 공돌공돌
,

예제 확인 및 소스(소스보기)

 

Posted by 공돌공돌
,

 

http://bboong100.cafe24.com/0905/calc.html

현재 까지 가능한 기능

텍스트창 오른쪽 정렬

엔터키로 연산

소수점 값 입력

위에 텍스트에 먼저 입력한 숫자와 연산자를 표시하고 연산 결과는 아래창에 출력되는 기능

연산자, 0, 소수점(.) 중복 입력시 처리 문제

'C' 버튼을 눌렀을 때 위 텍스트창도 초기화

 연산 결과 나오고 다시 연산자 버튼을 눌렀을 때 위 텍스트 창에 기존 수식이 계속 출력되던 문제 해결 

추가할 기능

처음 숫자 입력 하고 연산자 누르고 다른 연산자 눌렀을 때 나중에 누른 연산자로 대체되어야 하는 문제

백스페이스 눌렀을 때 생기는 오류들 ...


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<style type="text/css">
    .txtalign {
        text-align: right;
    }

</style>

<script type="text/javascript">
var str = "";
var str2 = "";
var flag = false;

function cal(num)
{
    //입력된 값이 숫자면 true 문자면 false
    if (!isNaN(num))
    {
        if (!flag)
        {
            str = "";
            document.getElementById('txt').innerHTML = '';
            //innerhtml 태그 - 지정된 태그의 값을 바꿔준다!
        }
        str += num;
        str2 += num;
        // 위 아래텍스트 창에 동시에넣어주고
        // 아래창만 출력한다
        document.getElementById('txt').innerHTML += num;
        flag = true;
    }
    //이전에 입력값이 숫자였으면
    else if (flag)
    {
        str2 += num;
        //기존에 입력된 숫자와 연산자를 위 텍스트창에 출력한다
        document.getElementById('txtcalc').innerHTML = str2;
        if (!isNaN(num))
        {
            str2.substring(0, str.length - 1);
            str2 += num;
            document.getElementById('txtcalc').innerHTML = str2;
        }
        flag = false;
    }
}

function answer()
{
    //수식이 연산자로 끝나면
    if (!flag)
    {
        alert('수식을 다시 입력해주세요!');
        return;
    }
    else
    {
        document.getElementById('txtcalc').innerHTML = str2;
        document.getElementById('txt').innerHTML = eval(str2);
        // 위 텍스트창에 연산한 결과값을 eval()함수로 계산 하고아래 텍스창  결과 출력
        document.getElementById('txtcalc').innerHTML = "";
        // 위 창에 내용을초기

        str2 = document.getElementById('txt').innerHTML;
        alert(str2);
    }
}

function enter(number)
{
    if (event.keyCode == 13)
    {
        answer();

    }
    else if ((event.keyCode >= 96 && event.keyCode <= 105))
    {
        cal(event.keyCode - 96);
    }

    else if (flag && ( event.keyCode == 107 || event.keyCode == 109 ||
                       event.keyCode == 106 || event.keyCode == 111 ||
                       event.keyCode == 110))
    {
        switch (event.keyCode) {

            case 107:cal('+');break;
            case 109:cal('-');break;
            case 106:cal('*');break;
            case 111:cal('/');break;
        }
    }
    //        else
    //        {
    //            alert('숫자 또는 연산자를 입력하세요!');
    //        }
}

function clearcal()
{
    str2 = "";
    flag = false;
    document.getElementById('txt').innerHTML = "수식을 입력하세요..";
    document.getElementById('txtcalc').innerHTML = "";
    // 텍스트창 초기화
}

function bs()
{
    document.getElementById('txt').innerHTML = str.substring(0, str.length - 1);
    str2 = str2.substring(0, str2.length - 1);
    document.getElementById('txtcalc').innerHTML = str2;
    if (str.length == 0)
        str = '0';
    // substring 으로 0부터 value 길이에서 -1 한 만큼의 길이를 출력한다
}

</script>
<title>계산기</title>
</head>
<body onkeydown="enter(cal);">
<form name="calc">
    <table border=1 width=200px height=200px cellpadding=0 cellspacing=0 align=center>

        <tr border=2>  <!-- 연산자 표시창  -->
            <td colspan=5 align=center height=20>
                <div id='txtcalc' name='txtcalc' class="txtalign" value=''></div>
                <div id='txt' name='txt' class="txtalign" value=''>수식을 입력하세요..</div>
            </td>
        </tr>

        <tr height=40px> <!-- 백스페이스, C -->
            <td colspan=5>
                <table border=1 width=100%>
                    <tr align=center>
                        <td width=33%><input type=button value='BackSpace' style="width:100%;" onclick=bs()></td>
                        <td width=33%><input type=button value='C' style="width:100%;" onclick=clearcal()></td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr align=center>
            <td width=25%><input type=button value='  1  ' onclick="cal('1')"></td>
            <td width=25%><input type=button value='  2  ' onclick="cal('2')"></td>
            <td width=25%><input type=button value='  3  ' onclick="cal('3')"></td>
            <td width=25%><input type=button value='  /  ' onclick="cal('/')"></td>
        </tr>
        <tr align=center>
            <td><input type=button value='  4  ' onclick="cal('4')"></td>
            <td><input type=button value='  5  ' onclick="cal('5')"></td>
            <td><input type=button value='  6  ' onclick="cal('6')"></td>
            <td><input type=button value='  *  ' onclick="cal('*')"></td>
        </tr>
        <tr align=center>
            <td><input type=button value='  7  ' onclick="cal('7')"></td>
            <td><input type=button value='  8  ' onclick="cal('8')"></td>
            <td><input type=button value='  9  ' onclick="cal('9')"></td>
            <td><input type=button value='  +  ' onclick="cal('+')"></td>
        </tr>
        <tr align=center>
            <td><input type=button value='  =  ' onclick="answer()"></td>
            <td><input type=button value='  0  ' onclick="cal('0')"></td>
            <td><input type=button value='  .  ' onclick="cal('.')"></td>
            <td><input type=button value='  -  ' onclick="cal('-')"></td>
        </tr>
    </table>
</form>
</body>
</html>

 

Posted by 공돌공돌
,

 

 

http://bboong100.cafe24.com/0903/calc.html

현재 까지 가능한 기능

텍스트창 오른쪽 정렬

엔터키로 연산

소수점 값 입력

위에 텍스트에 먼저 입력한 숫자와 연산자를 표시하고 연산 결과는 아래창에 출력되는 기능

연산자, 0, 소수점(.) 중복 입력시 처리 문제

'C' 버튼을 눌렀을 때 위 텍스트창도 초기화

추가할 기능

eval를 사용하지 않고 연산( +,- 등 연산자를 연속으로 입력 했을 때 에러 발생)

예외처리

연산 결과 출력 후 새로운 숫자 입력 했을 때 텍스트창이 초기화되지 않는 문제

 


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<style type="text/css">
 .txtalign {
  text-align: right;
 }

</style>

<script type="text/javascript">
 var str = "";
 var str2 = "";
 var flag = false;

 function cal(num)
 {
  //입력된 값이 숫자면 true 문자면 false
  if (!isNaN(num))
  {
   if (!flag)
   {
    str = "";
                document.getElementById('txt').innerHTML = '';
                //innerhtml 태그 - 지정된 태그의 값을 바꿔준다!
            }
   str += num;
   str2 += num;
            // 위 아래텍스트 창에 동시에넣어주고
            // 아래창만 출력한다
            document.getElementById('txt').innerHTML += num;
   flag = true;
  }
  //이전에 입력값이 숫자였으면
  else if (flag)
  {
   str2 += num;
            //기존에 입력된 숫자와 연산자를 위 텍스트창에 출력한다
            document.getElementById('txtcalc').innerHTML = str2;
   flag = false;
  }
 }

 function answer()
 {
  //수식이 연산자로 끝나면
  if (!flag)
  {
   alert('수식을 다시 입력해주세요!');
   return;
  }
  else
  {
   document.getElementById('txtcalc').innerHTML = str2;
   document.getElementById('txt').innerHTML = eval(str2);
            // 위 텍스트창에 연산한 결과값을 eval()함수로 계산 하고아래 텍스창  결과 출력
            document.getElementById('txtcalc').innerHTML = "";
            // 위 창에 내용을초기화

        }
 }

 function enter(number)
 {
  if (event.keyCode == 13)
  {
   answer();

        }
  else if ((event.keyCode >= 96 && event.keyCode <= 105))
  {
   cal(event.keyCode - 96);
  }

  else if (flag && ( event.keyCode == 107 || event.keyCode == 109 ||
       event.keyCode == 106 || event.keyCode == 111 ||
       event.keyCode == 110))
  {
   switch (event.keyCode){
    case 107:cal('+');break;
    case 109:cal('-');break;
    case 106:cal('*');break;
    case 111:cal('/');break;
   }
  }
  else
  {
   alert('숫자 또는 연산자를 입력하세요!');
  }
 }

 function clearcal()
 {
  str2 = "";
  flag = false;
  document.getElementById('txt').innerHTML = "수식을 입력하세요..";
  document.getElementById('txtcalc').innerHTML = "";
  // 텍스트창 초기화
 }


    function bs()
 {
  document.getElementById('txt').innerHTML = str.substring(0, str.length - 1);
  str2 = str2.substring(0, str2.length - 1);
  document.getElementById('txtcalc').innerHTML = str2;
  // substring 으로 0부터 value 길이에서 -1 한 만큼의 길이를 출력한다
 }
</script>
<title>계산기</title>
</head>
<body onkeydown="enter(cal);">
<form name="calc">
<table border=1 width=200px height=200px cellpadding=0 cellspacing=0 align=center>

   <tr border=2>  <!-- 연산자 표시창  -->
   <td colspan=5 align=center height=20>
    <div id='txtcalc' name='txtcalc' class="txtalign" value=''></div>
    <div id='txt' name='txt' class="txtalign" value=''>수식을 입력하세요..</div>
   </td>
  </tr>

    <tr height=40px> <!-- 백스페이스, C -->
        <td colspan=5>
            <table border=1 width=100%>
                <tr align=center>
                    <td width=33%><input type=button value='BackSpace' style="width:100%;" onclick=bs()></td>
                    <td width=33%><input type=button value='C' style="width:100%;" onclick=clearcal()></td>
                </tr>
            </table>
        </td>
    </tr>
    <tr align=center>
        <td width=25%><input type=button value='  1  ' onclick="cal('1')"></td>
        <td width=25%><input type=button value='  2  ' onclick="cal('2')"></td>
        <td width=25%><input type=button value='  3  ' onclick="cal('3')"></td>
        <td width=25%><input type=button value='  /  ' onclick="cal('/')"></td>
    </tr>
    <tr align=center>
        <td><input type=button value='  4  ' onclick="cal('4')"></td>
        <td><input type=button value='  5  ' onclick="cal('5')"></td>
        <td><input type=button value='  6  ' onclick="cal('6')"></td>
        <td><input type=button value='  *  ' onclick="cal('*')"></td>
    </tr>
    <tr align=center>
        <td><input type=button value='  7  ' onclick="cal('7')"></td>
        <td><input type=button value='  8  ' onclick="cal('8')"></td>
        <td><input type=button value='  9  ' onclick="cal('9')"></td>
        <td><input type=button value='  +  ' onclick="cal('+')"></td>
    </tr>
    <tr align=center>
        <td><input type=button value='  =  ' onclick="answer()"></td>
        <td><input type=button value='  0  ' onclick="cal('0')"></td>
        <td><input type=button value='  .  ' onclick="cal('.')"></td>
        <td><input type=button value='  -  ' onclick="cal('-')"></td>
    </tr>
</table>
</form>
</body>
</html>

 

Posted by 공돌공돌
,

현재 까지 가능한 기능

텍스트창 오른쪽 정렬

엔터키로 연산

소수점 값 입력

추가할 기능

eval를 사용하지 않고 연산( +,- 등 연산자를 연속으로 입력 했을 때 에러 발생)

위에 텍스트에 먼저 입력한 숫자와 연산자를 표시하고 연산 결과는 아래창에 출력되는 기능

예외처리

연산 결과 출력 후 새로운 숫자 입력 했을 때 텍스트창이 초기화되지 않는 문제

연산자, 0, 소수점(.) 중복 입력시 처리 문제

 

 

Posted by 공돌공돌
,

 

실습예제 -  http://bboong100.cafe24.com/0831/selection1.html

자바스크립트 셀렉트(javascript select) option 추가하기

주석은 오후 작성 예정

<html>
<head>
    <script type="text/javascript">

        var arr = ["영업-1","영업-2","영업-3"];
        var networkarr = ["N/W-1","N/W-2","N/W-3"];

        function daeli() {
            var targetObj = document.getElementById('a');
            if (document.agency.daelijeom[0].checked) {
                targetObj.length=0;
                for (var a = 0; a < arr.length; a++)
                {
                    targetObj.add(new Option(arr[a], arr[a]), [a]);
                }
            }
            else if (document.agency.daelijeom[1].checked) {
                targetObj.length=0;
                for (var a = 0; a < networkarr.length; a++)
                {
                    targetObj.add(new Option(networkarr[a], networkarr[a]), [a]);
                }
            }
        }


    </script>
    <title>sales/networdk agency</title>
</head>
<body>
<form name='agency'>
    <table border=1>
        <tr>
            <td> sales <input type=radio name='daelijeom' onclick='daeli();'></td>
            <td> N/W <input type=radio name='daelijeom' onclick='daeli();'></td>
        </tr>
    </table>
    <p><p><p>
    <table border=1>
        <tr>
            <td>aff <select name="a" id="a"></select></td>
        </tr>
    </table>
</form>
</body>
</html>

 

Posted by 공돌공돌
,

 

http://bboong100.cafe24.com/0830/calc.html

수정완료사항

텍스트 창(아래쪽) 오른쪽 정렬

소수점 연산 가능

추가예정사항

키보드 입력 가능(Enter키로 연산결과 나타내기)

eval 사용하지 않고 자바스크립트 직접 계산하기

텍스트창에 연산자 ( +, -, *, / )는 위 텍스트창에 출력하기

 


<html>
<head>
    <style type="text/css">
        .txtalign {
            text-align: right;
        }

    </style>

    <script type="text/javascript">
        var keycode = event.keyCode;
        function cal(num) {
            calc.txt.value += num;
        }

        function answer() {
            calc.txt.value = eval(document.calc.txt.value);

            // document.calc.txt.value 에 저장된 문자열을
            // 자바스크립트코드로 실행
        }
        function operator(){

        }
        //onkeydown - 모든 키를 눌렀을때(shift, alt, control, capslock 등의 키도 모두 인식한다.
                               단 한영변환,한자 등의 특수키는 인식못함.)
        //onkeyup - 모든 키를 눌렀다 땠을때(onkeydown 에서 인식하는 키들을 인식)
        //onkeypress - 실제로 글자가 써질때 (shift, enter 같은 키는 인식하지 못한다)

        function enter(eql) {
            if (event.keyCode == 13) {
                answer();
            }
        }

        function clearcal() {
            calc.txt.value = "";
            // 텍스트창 초기화
        }

        function bs() {
            calc.txt.value = calc.txt.value.substring(0, calc.txt.value.length - 1);
            // substring 으로 0부터 value 길이에서 -1 한 만큼의 길이를 출력한다
        }
    </script>
    <title>계산기</title>
</head>
<body>
<form name="calc">
    <table border=1 width=200px height=200px cellpadding=0 cellspacing=0 align=center>

        <tr border=2>  <!-- 숫자표시창 -->
            <td colspan=5 align=center><input type=text name="txtcalc" disabled></td>
        </tr>
        <tr border=2>  <!-- 숫자표시창 -->
            <td colspan=5 align=center><input type=text name="txt" disabled class=txtalign></td>
        </tr>
        <tr height=40px> <!-- 백스페이스, C -->
            <td colspan=5>
                <table border=1 width=100%>
                    <tr align=center>
                        <td width=33%><input type=button value='BackSpace' style="width:100%;" onclick=bs()></td>
                        <td width=33%><input type=button value='C' style="width:100%;" onclick=clearcal()></td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr align=center>
            <td width=25%><input type=button value='  1  ' onclick="cal('1')"></td>
            <td width=25%><input type=button value='  2  ' onclick="cal('2')"></td>
            <td width=25%><input type=button value='  3  ' onclick="cal('3')"></td>
            <td width=25%><input type=button value='  /  ' onclick="cal('/')"></td>
        </tr>
        <tr align=center>
            <td><input type=button value='  4  ' onclick="cal('4')"></td>
            <td><input type=button value='  5  ' onclick="cal('5')"></td>
            <td><input type=button value='  6  ' onclick="cal('6')"></td>
            <td><input type=button value='  *  ' onclick="cal('*')"></td>
        </tr>
        <tr align=center>
            <td><input type=button value='  7  ' onclick="cal('7')"></td>
            <td><input type=button value='  8  ' onclick="cal('8')"></td>
            <td><input type=button value='  9  ' onclick="cal('9')"></td>
            <td><input type=button value='  +  ' onclick="cal('+')"></td>
        </tr>
        <tr align=center>
            <td><input type=button value='  =  ' onclick="answer()"></td>
            <td><input type=button value='  0  ' onclick="cal('0')"></td>
            <td><input type=button value='  .  ' onclick="cal('.')"></td>
            <td><input type=button value='  -  ' onclick="cal('-')"></td>
        </tr>
    </table>
</form>
</body>
</html>


 

 

Posted by 공돌공돌
,

event.keycode 표

←(백스패이스) = 8
TAB = 9
ENTER = 13
SHIFT = 16
CTRL = 17
ALT = 18
PAUSEBREAK = 19
CAPSLOOK = 20
한/영 = 21
한자 = 25
ESC = 27

스패이스 = 32
PAGEUP = 33
PAGEDN = 34
END = 35
HOME =36

←(중간) = 37
↑(중간) = 38
→(중간) = 39
↓(중간) = 40

0 = 48
1 = 49
2 = 50
3 = 51
4 = 52
5 = 53
6 = 54
7 = 55
8 = 56
9 = 57
INSERT = 45
DELETE = 46

A = 65
B = 66
C = 67
D = 68
E = 69
F = 70
G = 71
H = 72
I = 73
J = 74
K = 75
L = 76
M = 77
N = 78
O = 79
P = 80
Q = 81
R = 82
S = 83
T = 84
U = 85
V = 86
W = 87
X = 88
Y = 89
Z = 90

윈도우(왼쪽) = 91
윈도우(오른쪽) = 92
기능키 = 93
0(오른쪽) = 96
1(오른쪽) = 97
2(오른쪽) = 98
3(오른쪽) = 99
4(오른쪽) = 100
5(오른쪽) = 101
6(오른쪽) = 102
7(오른쪽) = 103
8(오른쪽) = 104
9(오른쪽) = 105
.(오른쪽) = 110
/(오른쪽) = 111
*(오른쪽) = 106
+(오른쪽) = 107
-(오른쪽) = 109
F1 = 112
F2 = 113
F3 = 114
F4 = 115
F5 = 116
F6 = 117
F7 = 118
F8 = 119
F9 = 120
F10 = 121
F11 = 122
F12 = 123
NUMLOCK = 144
SCROLLLOCK = 145
=(중간) = 187
-(중간) = 189
`(왼쪽콤마) = 192
(중간) = 220

 

 

 

Posted by 공돌공돌
,

 

 

실행주소 : http://bboong100.cafe24.com/0828/calc1.html

풀 소스

<html>
<head>
    <script type="text/javascript">
        function cal(num) {
            calc.txt.value += num;
        }
        function answer() {
            calc.txt.value = eval(document.calc.txt.value);
            // document.calc.txt.value 에 저장된 문자열을
            // 자바스크립트코드로 실행
        }

        function clearcal() {
            calc.txt.value = "";
            // 텍스트창 초기화
        }

        function bs(){
            calc.txt.value = calc.txt.value.substring(0, calc.txt.value.length-1);
            // substring 으로 0부터 value 길이에서 -1 한 만큼의 길이를 출력한다
        }
    </script>
    <title>계산기</title>
</head>
<body>
<form name="calc">
    <table border=1 width=200px height=200px cellpadding=0 cellspacing=0>

        <tr border=2>  <!-- 숫자표시창 -->
            <td colspan=5 align=center><input type=text name="txt" disabled></td>
        </tr>
        <tr height=40px> <!-- 백스페이스, C -->
            <td colspan=5>
                <table border=1 width=100%>                                               
                    <tr align=center>
                        <td width=33%><input type=button value='BackSpace' style="width:100%;" onclick=bs()></td>
                        <td width=33%><input type=button value='C' style="width:100%;" onclick=clearcal()></td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr align=center>
            <td width=25%><input type=button value=1 onclick="cal('1')"></td>
            <td width=25%><input type=button value=2 onclick="cal('2')"></td>
            <td width=25%><input type=button value=3 onclick="cal('3')"></td>
            <td width=25%><input type=button value='/' onclick="cal('/')"></td>
        </tr>
        <tr align=center>
            <td><input type=button value=4 onclick="cal('4')"></td>
            <td><input type=button value=5 onclick="cal('5')"></td>
            <td><input type=button value=6 onclick="cal('6')"></td>
            <td><input type=button value=* onclick="cal('*')"></td>
        </tr>
        <tr align=center>
            <td><input type=button value=7 onclick="cal('7')"></td>
            <td><input type=button value=8 onclick="cal('8')"></td>
            <td><input type=button value=9 onclick="cal('9')"></td>
            <td><input type=button value=+ onclick="cal('+')"></td>
        </tr>
        <tr align=center>
            <td> </td>
            <td><input type=button value=0 onclick="cal('0')"></td>
            <td><input type=button value='=' onclick="answer()"></td>
            <td><input type=button value='-' onclick="cal('-')"></td>
        </tr>
    </table>
</form>
</body>
</html>

 

Posted by 공돌공돌
,

브라우저 객체 모델 BOM(Browser Object Model)

 웹 브라우저와 관련된 객체의 집합을 의미

 대표적인 BOM으로는 window, location, navigator, history, screen, document가 있다

 

Window 객체

 브라우저 객체들의 계층구조 에서 최상위에 있는 객체

 자바스크립트로 하는 모든 작업이 Window객체 안에서 이루어짐

메소드 이름

설명

open(URL, name, features, replace)

새로운 window 객체를 생성

setTimeout(function, millisecond)

일정 시간 후에 함수를 한 번 실행

setInterval(function, millisecond)

일정 시간마다 함수를 반복해서 실행

clearTimeout(id)

일정 시간 후에 함수를 한 번 실행하는 것을 중지

clearInterval(id)

일정 시간마다 함수를 반복하는 것을 중단

moveTo(x,y)

윈도우의 위치를 x, y만큼 이동한다                       

focus()

윈도우에 초점을 맞춘다

blur()

윈도우에 초점을 제거한다

close()

윈도우를 닫는다

 

Window 객체의 onload 이벤트 속성

문서객체의 속성중 on으로 시작하는 속성을 이벤트 속성이라 하며 함수를 할당해야 한다

window 객체가 로드가 완료되고 자동으로 onload()에 할당된 함수를 실행한다

 

 

Screen 객체

 웹 브라우저의 화면이 아니라 운영체제 화면의 속성을 가지는 객체

속성

설명

width

화면의 너비

height

화면의 높이

availWidth

실제 화면에서 사용가능한 너비

availHeight

실제 화면에서 사용가능한 높이

colorDepth

사용 가능한 색상 수

pixelDepth

한 픽셀당 비트 수

 

location 객체

 브라우저의 주소 표시줄과 관련된 객체

 프로토콜의 종류, 호스트 이름, 문서 위치 등의 정보를 갖는다

메소드 이름

설명

assign(link)

현재 위치를 이동

reload()

새로 고침

replace(link)

현재 위치를 이동( 뒤로 가기 불가능)

 

navigator 객체

웹페이지를 실행하고 있는 브라우저에 대한 정보를 갖는다

속성

설명

appCodeName

브라우저의 코드명

appName

브라우저의 이름

appVersion

브라우저의 버전

platform

사용중인 운영체제의 시스템 환경

userAgent

브라우저의 전체적인 정보

 

 

Posted by 공돌공돌
,

문서 객체 모델 ( DOM, Document Object Model)

웹 브라우저가 HTML 페이지를 인식하는 방식

document 객체와 관련된 객체의 집합

html 페이지에 존재하는 태그를 자바스크립트에서 이용할 수 있는 객체로 만드는 것

 

메소드 이름

설명

createElement(tagName)

요소 노드 생성

createTextNode(text)

텍스트 노드 생성

appendChild(node)

객체에 노드를 연결

setAttribute(name, value)

객체의 속성을 지정

getAttribute(name)

객체의 속성을 가져옴

getElementById(id)

태그의 id속성이 id와 일치하는 객체를 가져옴

getElementsByName(name)

태그의 name속성이 name과 일치하는 문서 객체
를 배열로 가져온다

getElementsByTagName(tagName)

tagName과 일치하는 문서 객체를 배열로 가져온다

Posted by 공돌공돌
,
<script type="text/javascript">
        window.onload = function () {
            // 문서 객체를 가져옵니다.
            var header = document.getElementById('header');
            // 문서 객체의 스타일을 바꿔줍니다.
            header.style.border = '2px Solid Black';
            header.style.color = 'Orange';
            header.style.fontFamily = 'Helvetica';
            header.style.backgroundColor = 'black';
        };
</script>
<body>
    <h1 id="header">Header</h1>
</body>

    위에 기술한 스타일 외에도 다양한 속성들이 있다 


    문서 객체의 스타일은 css와 속성이름이 약간 다르다


    자바스크립트는 식별자 '-' 를 사용할 수 없으므로 css의 background-color 속성을

     backgroundColor 로 나타낸다

 

Posted by 공돌공돌
,

   <script type="text/javascript">
        window.onload = function () {
            var headers = document.getElementsByTagName('h1');
            //변수 headers 는 문서 객체를 가지는 배열이며 html 페이지의 h1 태그가 순서대로 들어감
            for (var i = 0; i < headers.length; i++) {
                // 문서 객체의 속성 변경
                headers[i].innerHTML = 'With getElementsByTagName()';
            }
        };
    </script>

    <body>
    <h1>Header</h1>
    <h1>Header</h1>
    </body>

    getElementByName()는 getElementById() 메서드와 달리 한번에 여러개의 문서 객체를 가져올 수 있다
    getElementByName()는 배열이므로 반복문을 사용할 수 있지만 for in 반복문을 사용하면
    문서 객체 이외의 속성에도 접근하기 때문에 for문 을 사용해야 한다

 

With getElementsByTagName()

With getElementsByTagName()


 

Posted by 공돌공돌
,
<script type="text/javascript"> window.onload = function () { // 문서 객체를 가져옵니다. var header1 = document.getElementById('header_1'); // id 속성이 header_1 인 태그를 가져와서 header1 에 저장 var header2 = document.getElementById('header_2'); // id 속성이 header_2 인 태그를 가져와서 header2 에 저장 // 문서 객체의 속성을 변경합니다. header1.innerHTML = 'with getElementById()'; //Header 대신 with getElementById() 로 변경 header2.innerHTML = 'with getElementById()'; //Header 대신 with getElementById() 로 변경 }; </script> <h1 id="header_1">Header</h1> <h1 id="header_2">Header</h1>

 

 

with getElementById()

with getElementById()

'개발개발 > 자바스크립트' 카테고리의 다른 글

문서 객체의 스타일  (0) 2012.08.27
문서 객체 가져오기(getElementByName())  (0) 2012.08.27
문서 객체의 속성(setAttribute  (0) 2012.08.27
문서 객체 연결  (0) 2012.08.27
Navigator 속성 보기  (0) 2012.08.27
Posted by 공돌공돌
,
<script type="text/javascript"> window.onload = function () { var img = document.createElement('img'); img.setAttribute('src', 'kkola.jpg'); img.setAttribute('width', 500); img.setAttribute('height', 350); img.setAttribute('data-property', 350); // img.setAttribute()이 // <img src = "winter.jpg" width = "500" height="350" data-property="350"> // 와 같은 결과를 나타낸다 document.body.appendChild(img); // 노드 연결 }; </script>

 

'개발개발 > 자바스크립트' 카테고리의 다른 글

문서 객체 가져오기(getElementByName())  (0) 2012.08.27
문서 객체 가져오기(getElementById() )  (0) 2012.08.27
문서 객체 연결  (0) 2012.08.27
Navigator 속성 보기  (0) 2012.08.27
location 객체 속성 보기  (0) 2012.08.27
Posted by 공돌공돌
,

   <script type="text/javascript">
        window.onload = function () {
            var header = document.createElement('h1');
            //문서 객체 header 생성
            var textNode = document.createTextNode('Hello DOM');
            // 문서객체 hello dom 생성

            header.appendChild(textNode);
            // header 문서 객체에 textnode 문서 객체 노드 연결
            document.body.appendChild(header);
            // body 문서 객체에 header 문서객체 추가
        };
    </script>

 

Hello DOM

'개발개발 > 자바스크립트' 카테고리의 다른 글

문서 객체 가져오기(getElementById() )  (0) 2012.08.27
문서 객체의 속성(setAttribute  (0) 2012.08.27
Navigator 속성 보기  (0) 2012.08.27
location 객체 속성 보기  (0) 2012.08.27
screen 객체  (0) 2012.08.27
Posted by 공돌공돌
,

  <script type="text/javascript">
        var output = '';
        for (var key in navigator) {
            output += '* ' + key + ' : ' + navigator[key] + '\n';
        }
        alert(output);
    </script>

 


'개발개발 > 자바스크립트' 카테고리의 다른 글

문서 객체의 속성(setAttribute  (0) 2012.08.27
문서 객체 연결  (0) 2012.08.27
location 객체 속성 보기  (0) 2012.08.27
screen 객체  (0) 2012.08.27
window 객체 절대 이동  (0) 2012.08.27
Posted by 공돌공돌
,

    <script type="text/javascript">
        var output = '';
        for (var key in location) {
            output += '* ' + key + ' : ' + location[key] + '\n';
        }
        alert(output);

    </script>

 

'개발개발 > 자바스크립트' 카테고리의 다른 글

문서 객체 연결  (0) 2012.08.27
Navigator 속성 보기  (0) 2012.08.27
screen 객체  (0) 2012.08.27
window 객체 절대 이동  (0) 2012.08.27
Window 객체  (0) 2012.08.27
Posted by 공돌공돌
,

  <script type="text/javascript">
        var child = window.open('', '', 'width=300, height=200');
        // 가로300, 세로 200인 윈도우창을 만든다
        var width = screen.width;
        var height = screen.height;
        //화면 너비,높이

        child.moveTo(0, 0);
        child.resizeTo(width, height);
        //화면 너비 높이를 width, height로 지정

        setInterval(function () {
            child.resizeBy(-20, -20);
            // 크기는 -20씩 작아지고
            child.moveBy(10, 10);
            // 위치는 10씩 이동한다
        }, 2000);
    </script>

화면이 가운데 쪽으로 점점 작아진다

'개발개발 > 자바스크립트' 카테고리의 다른 글

Navigator 속성 보기  (0) 2012.08.27
location 객체 속성 보기  (0) 2012.08.27
window 객체 절대 이동  (0) 2012.08.27
Window 객체  (0) 2012.08.27
기본 내장 객체 _ 자주 쓰는 메소드  (0) 2012.08.27
Posted by 공돌공돌
,

  <script type="text/javascript">
        var child = window.open('', '', 'width=800, height=600');
        // 가로 800 세로 600인 창을 만든다
        child.moveTo(0, 0);

        setInterval(function () {
            // 함수 반복 실행 메소드
            child.moveBy(10, 10);
            //1초에 한번씩 가로10, 세로 10만큼 창이 움직인다
        }, 1000);
        // 1초마다 반복
    </script>

 

'개발개발 > 자바스크립트' 카테고리의 다른 글

location 객체 속성 보기  (0) 2012.08.27
screen 객체  (0) 2012.08.27
Window 객체  (0) 2012.08.27
기본 내장 객체 _ 자주 쓰는 메소드  (0) 2012.08.27
기본내장객체 - Math  (0) 2012.08.27
Posted by 공돌공돌
,
<!--StartFragment-->    <script type="text/javascript">
        // 윈도우가 로드될 때
        window.onload =
        function () {
            alert('3초후 이 페이지는 종료됩니다.');
            // 3초 후에 함수를 실행합니다.
            window.setTimeout(
                    function () {
                        window.close();
                    }, 3000);
            //3초 후에 window.close() 실행
        };
    </script>

 

'개발개발 > 자바스크립트' 카테고리의 다른 글

screen 객체  (0) 2012.08.27
window 객체 절대 이동  (0) 2012.08.27
기본 내장 객체 _ 자주 쓰는 메소드  (0) 2012.08.27
기본내장객체 - Math  (0) 2012.08.27
기본내장객체 - Date  (0) 2012.08.27
Posted by 공돌공돌
,

기본 내장 객체
 
기본 자료형과 객체의 차이

속성과 메소드는 객체가 가질 수 있는 것인데 기본 자료형에도 속성과 메소드가 있다

기본 자료형의 속성이나 메소드를 사용하면 기본 자료형이 자동으로 객체로 변환된다!

대신 기본자료형은 메소드나 속성이 추가는 되지 않는다

 

Object 객체

자바스크립트의 가장 기본적인 내장객체

Object 생성자 함수로 만든 인스턴스

자주 사용하는 편은 안디ㅏ

Object 객체는 총 7개의 메소드를 갖는다

모든 기본 내장 객체는 Object객체를 기본적으로 만들어지기 때문에 다른 기본 내장객체

들 또한 일곱가지의 메소도를 갖는다

 

메소드 이름

설명

constructor()

객체의 생성자 함수를 나타냄

hasOwnProperty(name)

객체가 name속성을 가지고 있는지 확인

isPrototypeof(object)

객체가 object의 프로토타입인지 검사

propertyIsEnumerable(name)

반복문을 사용해 열거 할 수 있는지 확인

toLocaleString()

객체를 호스트 환경에 맞는 언어의 문자열로 바꿈

toString()

객체를 문자열로 바꿈

valueOf()

객체의 값을 나타

 

 

 

 

 

 

 

Number 객체

문자를 숫자로 바꾸어 주는 역할

자바스크립트에서 가장 단순함

메소드 이름

설명

toExponential()

숫자를 지수 표시로 나타내는 문자열을 만듦

toFixed()

숫자를 고정소수좀 표시로 나타낸 문자열을 만듦

toPrecision()

숫자를 길이에 따라 지수 표시 또는 고정 소수점 표시로 나타낸 문자열을 만듦

 

String 객체

 문자의 모양을 지정하거나 문자열을 처리하기 위한 객체

 String 객체는 매우 많은 메소드들이 있기 때문에 그 중에서도 가장 많이 쓰는

 메소드를 정리 했다

 HTML관련 메서드는 9장에서 문서 객체를 할 때 공부한다

메소드 이름

설명

charAt(position)

position에 위치하는 문자를 리턴

indexOf(searchString, position)

앞에서부터 일치하는 문자열의 위치를 리턴

match(regExp)

문자열 내에 regExp가 있는지 확인

replace(regExp,replacement)

regExp replacement로 바꾼뒤 리턴

search(regExp)

regExp와 일치하는 문자열의 위치를 리턴

toLowerCase()

문자열을 소문자로 바꿔 리턴

toUpperCase()

문자열을 대문자로 바꿔 리턴

 

Array객체

배열을 만들 때 사용하는 내장 객체,

여러가지 자료를 쉽게 관리할 수 있게 도와주는 객체

메소드 이름

설명

concat()

매개변수로 입력한 배열의 요소를 모두 합쳐 배열을 만들어 리턴

join()

배열 안의 모든 요소를 문자열로 만들어 리턴

pop()

배열의 마지막 요소를 제거하고 리턴

push()

배열의 마지막 부분에 새로운 요소를 추가

reverse()

배열의 요소 순서를 뒤집는다

slice()

배열 요소의 지정한 부분을 리턴

sort()

배열의 요소를 정렬하고 리턴

Date객체

 날짜와 시간을 표시하는 객체  

메소드 이름

설명

getDate()

,,’, ‘의 정보

getDay()

요일 정보

getMonth()

의 정보

getFullYear()

4자리 년도 정보

getYear()

2자리의 년도 정보

getHours()

시간, , 중 시간 정보

getMinutes()

분 정보

getSecond()

정보

 set*()

각 메소드명에 맞는 값들을 지정한다

  Math객체

 수학과 관련된 메소드를 갖는 객체

메소드 이름

설명

abs(x)

x의 절대값

cell(x)

x보다 크거나 같은 가장 작은 정수

floor(x)

x보다 작거나 같은 가장 작은 정수

max(x,y,z)

x,y,z 중에 가장 큰 값

min(x,y,z)

x,y,z 중에 가장 작은 값

random()

0부터 1까지의 임의의 수

round(x)

x를 반올림

 

'개발개발 > 자바스크립트' 카테고리의 다른 글

window 객체 절대 이동  (0) 2012.08.27
Window 객체  (0) 2012.08.27
기본내장객체 - Math  (0) 2012.08.27
기본내장객체 - Date  (0) 2012.08.27
기본내장객체 - Array - sort  (0) 2012.08.27
Posted by 공돌공돌
,
 <script type="text/javascript">
        var a = -200;
        var b = 30;
        var c = 21.5;
        var abs = Math.abs;
        var max = Math.max;
        var min = Math.min;
        var random = Math.random;
        var round = Math.round;

        alert(abs(a));
        alert(max(a, b, c));
        alert(min(a, b, c));
        alert(random());
        alert(round(c));
    </script>

 

Posted by 공돌공돌
,

 <script type="text/javascript">
        var date = new Date(1988, 1, 11);

        var output = '';
        output += '★toDateString: ' + date.toDateString() + '\n';
        // 날짜를 문자열 값으로 반환
        output += '★toGMTString: ' + date.toGMTString() + '\n';
        //  그리니치 표준시(GMT)를 사용하여 문자열로 변환된 일자를 반환
        output += '★toLocaleDateString: ' + date.toLocaleDateString() + '\n';
        // 현재 일자를 로케일을 사용하여 문자열로 반환
        output += '★toLocaleString: ' + date.toLocaleString() + '\n';
        //  현재 일자와 시간을 로케일을 사용하여 문자열로 반환
        output += '★toLocaleTimeString: ' + date.toLocaleTimeString() + '\n';
        // 현재 시간을 로케일을 사용하여 문자열로 반환
        output += '★toString: ' + date.toString() + '\n';
        // Date 객체를 나타내는 문자열을 반환
        output += '★toTimeString: ' + date.toTimeString() + '\n';
        // 현재 시간을 표준시간을 사용하여 시간 문자열로 반환
        output += '★toUTCString: ' + date.toUTCString() + '\n';
        // 협정 세계 표준시(UTC)를 사용하여 문자열로 변환된 일자를 반환
        alert(output);

    </script>


Posted by 공돌공돌
,

<script type="text/javascript">
        var array = [52, 273, 103, 32];
        array.sort();
        alert(array);
    </script>

 

sort()메소드를 사용해서 네개의 요소를 문자열 오름차순으로 정렬한다

'개발개발 > 자바스크립트' 카테고리의 다른 글

기본내장객체 - Math  (0) 2012.08.27
기본내장객체 - Date  (0) 2012.08.27
기본내장객체 - toUpperCase(), toLowerCase();  (0) 2012.08.27
기본내장객체 - Number  (0) 2012.08.27
기본내장객체 - object  (0) 2012.08.27
Posted by 공돌공돌
,

<script type="text/javascript">
        var word1 = 'abcdefg';
        var word2 = 'ABCDEFG';

        word1 = word1.toUpperCase();
        // 소문자를 대문자로
        word2 = word2.toLowerCase();
        // 대문자를 소문자로

        alert(word1);
        alert(word2);
    </script>

 

                                             


'개발개발 > 자바스크립트' 카테고리의 다른 글

기본내장객체 - Date  (0) 2012.08.27
기본내장객체 - Array - sort  (0) 2012.08.27
기본내장객체 - Number  (0) 2012.08.27
기본내장객체 - object  (0) 2012.08.27
상속  (0) 2012.08.27
Posted by 공돌공돌
,

<script type="text/javascript">
        var number = 273.5210332;
        var output = '';
        output += number.toFixed(1) + '\n';
        // 소수점 첫째 자리까지 자르기
        output += number.toFixed(4);
        // 소수점 넷째 자리까지 자르기
        alert(output);

</script>


 

 

'개발개발 > 자바스크립트' 카테고리의 다른 글

기본내장객체 - Array - sort  (0) 2012.08.27
기본내장객체 - toUpperCase(), toLowerCase();  (0) 2012.08.27
기본내장객체 - object  (0) 2012.08.27
상속  (0) 2012.08.27
getter,setter  (0) 2012.08.27
Posted by 공돌공돌
,