window.onload = function() {

  //문서의 모든 내용(이미지 포함)이 다운로드 되면 실행

}


jQuery(window).load( function() {

  //문서의 모든 내용(이미지 포함)이 다운로드 되면 실행

});

<html>

<body>

 <script type="text/javascript" src="./jquery-1.7.1.js"></script>

 <script language="javascript">

 

  $(document).ready(function(){

  $('#vgSortApp').change(function(){

    if( $('#vgSortApp option:selected').val() == "a"){

    alert("a");

    }else{


    }

  });

  });

 

 </script>

 <body>

 <select id="vgSortApp">

  <option value="">------</option>

  <option value="a">a항목</option>  

  <option value="b">b항목</option>  

 </select>  


jQuery("#inputCount").get(0).length  ;  // 셀렉트박스 길이

jQuery("#inputCount").get(0).options[0].selected = true; //첫번째 항목이 선택되게

 

 //옵션추가

for(var i=0; i<=count; i++){
   jQuery("#inputCount").get(0).options[i] = new Option(i + "개", i);  }

 

//옵션 초기화

for (var i = jQuery("#"+objName).get(0).length-1; i>=1; i--)
{
     jQuery("#"+objName).get(0).options[i] = null;
}

 

document.getElementById("inputCount").reInitializeSelectBox(102);    //이건 selectbox에 css가 안먹어서 js로 억지로 만들어 끼워 넣었는데 가로 size가 잘 안먹어서 다시 생성해주는 스크립트로 넣었음. 102는 넓이

 

 

<select id="inputCount" name="inputCount">
        <option value="">선택수량</option>
        <option value="1">1개</option>
</select>

/*

DOM 스크립트

*/


document.createElement("p")

document.createTextNode("")


node.cloneNode(false)

node.nodeType()


node.nodeValue()

document.getElementById("description").firstChild.nodeValue

attribute node="description" 인 요소노드의 firstChild 는 textNode 이다. 



document.getElementById(element node)


document.getElementsByTagName(element node)

<> document.createTextNode("Hello world")


document.body.appendChild(para)

document.removeChild(message)

element.insertBefore(newNode, targetNode)

element.replaceChild(newChild, oldChild)


element.setAttribute(attributeName, attributeValue) - element 요소만 가능

element.setAttribute(attribute, Value )

node.hasChildNodes()

node.childNodes.length


document.childNodes[0].nodeName == "HTML"

node.lastChild == node.childNodes[element.childNodes.length - 1]




document.body.appendChild(placeholder);

document.body.appendChild(description);


var gallery = document.getElementById("imagegallery");

gallery.parentNode.insertBefore(placehorder, gallery);


addLoadEvent();

addLoadEvent();


insertAfter() {}



/*

HTML DOM

*/


document.getElementByTagName("title").firstChild.nodeValue;


var w = window.open();

w.document.open();

w.document.write

w.document.close();

//write() 글이 쓰여진 새창을 띄운후 close한다


document.getElementById("w3c").taget = "_blank";

// 새창 띄우기.

// target


<area id="venus" shape="circle"

coords="124,58,8"

alt="Venus"

href="venus.htm?id=venus" />


document.getElementById("venus").host == "www.w3scholls.com"

getElementById("venus").hostname

getElementById("venus").pathName == "/jsref/venus.html"

getElementById("venus").search == "?id=venus"

getElementById("venus").shape == "circle"


document.getElementById("button1").form.id

document.getElementById("button1").parentNode.getAttribute("id")


<form id="frm1" accept-charset="ISO-8859-1">

document.getElementById("frm1").acceptCharset == "ISO-8859-1"


/*

document.getElementById("frm1").length


if(!document.getElementById) return false;

if(!document.getElementByTagName) return false;

if(!document.getElementByid("frm1")) return false;

var frm = document.getElementById("frm1");

var tagFrm = frm.getElementByTagName.childNodes;

for(var i=0; i<tagFrm.length; i++){

 if(!tagFrm[i]) return false;

 document.write( tagFrm[i] );

}

*/


<iframe id="myframe" src="/default.asp">

document.getElementById("myframe").align="right";

// 글 오른쪽에 iframe이 위치함


<form onmousedown="whichButton(event)">

if( event.button == 2) { alert("you clicked the right mouse button!"); }

else { alert("you clicked the left mouse button!"); }


Uncaught TypeError: undefined is not a function


'Client Standard > JavaScript & jQuery' 카테고리의 다른 글

select box Option 속성 클릭 시 나타나는 Behavior  (0) 2012.07.22
jQuery select box node 접근방법  (0) 2012.07.20
DOM 객체에 관하여 주저리  (0) 2012.07.20
getCookie()  (0) 2012.07.20
jQuery selectbox  (0) 2012.07.20

<head>

<script language="javascript">

function GetCookie(name){

  var arg = name + "="; // arg 선언동시에 "name="를받아 대입.

  var alen = arg.length;// arg변수의 길이

  var clen = document.cookie.length; //총 쿠키의 길이

  var i = 0;

  while(i < clen){ //0부터 총쿠키의 길이 까지 반복문 돌림.

    var j = i + alen; //j 변수선언과 동시에 0 + arg변수의 길이를 합한 값을 대입.

                      //j는 나중에 시작지점이 중간지점부터 되게하려고 선언되어 졌다. (getCookieValue()때)

    if(document.cookie.substring(i, j) == arg){ //0번째 인덱스부터 0+arg길이까지 문자열을 가져올때 arg와 동일하다면,

                                                // 즉, 쿠키값이 하나이상이 있다면, (하나이상이 있는지는 getCookieValue()함수로 파악)

                                                //substr()을 쓴다면 0번째 인덱스부터 0+alen개의 문자열을 가져올때 처럼 해석됨.

      return getCookieVal(j); // getCookieVal()함수 호출하여 그 함수에대한 return값을 반환.

    }else{ // 0번째 인덱스부터 0+alen번째 인덱스값까지 문자열을 가져올때 arg와 다르다면,

           // 즉, 쿠키값이 하나도 없다면,

      i = document.cookie.indexOf(" ", i) + 1; // 0번째 인덱스부터(즉, 맨처음부터) 공백인 문자열을 찾아 파싱한 값+1 을 i에다 재선언함

                                               //여기서 공백인 문자열을 못찾는다면,

    }if(i == 0) break; // break걸려,

  }return null; // 최종적으로, null값 반환.

}function SetCookie(name, value){  

  var argv = SetCookie.arguments; // argv변수는 SetCookie()함수의 파라미터 정보의 배열을 가짐.

                                  // argv[0]은 첫 번째 파라미터를 의미함

  var argc = SetCookie.arguments.length; //argc변수는 파라미터 개수를 가짐

  var expires = (argc > 2) ? argv[2] : null;  // 논리연산자를 이용하여 파라미터 값을 넣을지 null값을 넣을지 결정

  var path = (argc > 3) ? argv[3] : null;  

  var domain = (argc > 4) ? argv[4] : null;  

  var secure = (argc > 5) ? argv[5] : false;  

  document.cookie = name + "=" + encodeURI(value) +    //전달된 값을 연결하여 쿠키형식의 문자열을 만들어

  ((expires == null) ? "" : ("; expires=" + expires.toUTCString())) +   // 최종적인 문자열이

  ((path == null) ? "" : ("; path=" + path)) +    // document.cookie에 저장되어

  ((domain == null) ? "" : ("; domain=" + domain)) +    //새로운 쿠키가 생성

  ((secure == true) ? "; secure" : "");

}function DeleteCookie(name) {  

  var exp = new Date();  

  exp.setTime(exp.getTime() - 1);   

  var cval = GetCookie(name);

  document.cookie = name + "=" + cval + "; expires=" + exp.toUTCString();

}

 var exp = new Date(); //Date()함수를 선언하여 exp에 대입 (쿠키의 자동삭제기간을 생성하기 위함)

 exp.setTime(exp.getTime() + (24*60*60*1000)); //setTime()에서는 밀리초단위를 1로 둔다 즉, 1= 0.001초 1000=1초;1분*60=1시간*24=하루

function amt(){ //방문 횟수 출력 main함수

  var count = GetCookie('count'); //count에 getcookie()함수 대입.

  if(count == null){ // 누적되있는 cookie값이 없다면 == (정수로 1 도 없다면)

    SetCookie('count','1'); //SetCookie()에 getCookie(1)과 value 1을 넣음.

    return 1; //그후 1을 반환.

  }else{ //누적되있는 cookie값이 있다면 == (정수로 1 이상이 있다면)

    var newcount = parseInt(count) + 1; //GetCookie('count')에 저장되있는 문자열을 10진수화하여 + 1 하여 newcount 재선언.

    DeleteCookie('count'); //현재 가지고 있는 GetCookie('count') 값 삭제

    SetCookie('count', newcount, exp); //다시 GetCookie('count')에 +1누적되있는 값과 자동삭제날짜를 넣어 SetCookie시키고,

    return count; // 현 count를 정수로 반환 (즉, 예전 count+1를 반환)

  }

}function getCookieVal(offset){ //GetCookie()함수에서 j파라미터값을 받아,

  var endstr = document.cookie.indexOf(";", offset); // cookie내에서 offset(시작지점)부터 시작하여 ;를 파싱 한다

  if (endstr == "-1"){//cookie에서의 offset지점부터 문자열 ;를 파싱하지 못한다면

                      //GetCookie()함수에서 하지못한 총쿠키길이 파악.

    endstr = document.cookie.length; //endstr는 총 쿠키길이가 되고

    return decodeURI(document.cookie.substring(offset, endstr)); 

    // offset시작지점부터 총길이의 endstr갯수(총쿠키길이) 만큼 문자열을 잘라 count로 디코딩함

}}

</script>

<body>

<script language="javascript">

document.write("당신은 <font Color=red><b>" + amt() + "</b></font> 째 방문객입니다.");

</script>

</body>


값 선택

 $("#selectID option[value="+val+"]").attr("selected",true);

선택된 값 Value
$("#selectID option:selected").val();

$("select[name="+name+"]").val();

인덱스값
 $("#selectID option").index($("#SELECTID option:selected"));

맨 끝에 값 추가
 $("#selectID").append("<option value=5>5</option>");

맨 앞에 값 추가
$("#selectID").prepend("<option value=0>0</option>");

인덱스로 변경
$("#selectID option:eq("+index+")").replaceWith("<option value=2>2</option>");

+ Recent posts