본문 바로가기

개발하자/자바스크립트

(110)
자바스크립트 천단위 콤마찍기 (정규식) function addCommas(x) { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); }
배열의 값들을 원하는 순서대로 출력하기 td{ border:2px solid navy; }       var dataset=[ {"addr":"가좌동","id":"aa","pw":"11","tel":"010"}, {"addr":"호탄동","id":"bb","pw":"22","tel":"011"}, {"addr":"칠암동","id":"cc","pw":"33","tel":"012"} ]; var title=["id","pw","addr","tel"]; var cnt=0; document.write(""); document.write(""); for(var i in title){ document.write(""+title[i]+""); } document.write(""); for(var index in dataset){ document...
배열의 키를 이용해서 값 뽑아내기 var obj={ a:{b:100,c:function(){return 200;}}, d:[400,500,600] }; document.write(obj.a.b+""); document.write(obj.a.c()+""); document.write(obj.d[0]+""); document.write(obj.d[1]+""); document.write(obj.d[2]);
Button.prototype.setColor a.js ==== function Button(a,b){ var inputTag=document.createElement("input"); inputTag.type="button"; inputTag.id=a; inputTag.className=b; this.owner=inputTag; this.appendTo=function(container){ container.appendChild(inputTag); } this.addActionListener=function(callbackFunc){ inputTag.onclick=callbackFunc; } } a.html ======
객체생성해서 appendChild하기 이전처럼 하면 무조건 buttonContainer에만 append하게 되는데 이렇게 하면 그때그때 달라지게 소스를 만들수있다. a.js ==================================== function Button(a,b){ var inputTag=document.createElement("input"); inputTag.type="button"; inputTag.id=a; inputTag.className=b; this.appendTo=function(container){ container.appendChild(inputTag); } this.addActionListener=function(callbackFunc){ inputTag.onclick=callbackFunc; } } a.ht..
객체생성이용,외부js파일이용,클릭이벤트 등록하기 a.js ==== function Button(a,b){ var inputTag=document.createElement("input"); inputTag.type="button"; inputTag.id=a; inputTag.className=b; buttonContainer.appendChild(inputTag); this.addActionListener=function(callbackFunc){ inputTag.onclick=callbackFunc; } } b.html ======
객체생성 이용해서 버튼만들어서 css적용하기 a.js ========================== function Button(a,b){ var inputTag=document.createElement("input"); inputTag.type="button"; inputTag.id=a; inputTag.className=b; buttonContainer.appendChild(inputTag); }
외부파일로 css스타일 적용 시키고 js이벤트 주기 a.js ================================== window.onload=function(){ fontTag.onclick=function(){ alert("홍길동"); } } c.css =================================== font { color:red; } a.html ======================================= aaa