//targetStr : 전체 문자열
//before : 찾을 문자열
//after : 바뀐 후 내용
targetStr.split( before ).join( after );
생각하는 족족 고.따.구 냐..
자바스크립트 공부 하기.
http://www.crockford.com/javascript/inheritance.html
여러모로 유용한 트림 함수를 자바스크립트의 String객체게 바로 붙여서 사용할 수 있도록 하는 방법입니다.
좌/우/양쪽/모든공백을 아래와 같이 사용할 수 있습니다.
String.prototype.trim=function(){return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');};
String.prototype.ltrim=function(){return this.replace(/^\s+/,'');}
String.prototype.rtrim=function(){return this.replace(/\s+$/,'');}
String.prototype.fulltrim=function(){return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,'').replace(/\s+/g,' ');}
화면에서 많은 내용이 담긴 페이지를 작업할 때
그냥 프린트하면 화면전체가 프린트돼 제대로 나오지 않는 경우가 많지요?
그럴때에는 내용이 들어간 부분만 프린트할 수 있는 이 스크립트를 써봅시다!
step.01
먼저 프린트 되길 원하는 영역을 div로 묶어줍니다.
<div id="box">
프린트 되야하는 영역
</div>
step.02
인쇄하기 버튼을 따로만들어 링크를 걸어줍니다.
<a href="#" onclick="printArea()">인쇄하기</a>
step.03
그리고 이 자바스크립트를 맨 밑에 넣어줍니다.
<script type="text/javascript">
<!--
var initBody;
function beforePrint() {
boxes = document.body.innerHTML;
document.body.innerHTML = box.innerHTML;
}
function afterPrint() {
document.body.innerHTML = boxes;
}
function printArea() {
window.print();
}
window.onbeforeprint = beforePrint;
window.onafterprint = afterPrint;
-->
</script>
단점은 IE에서만 되면, 그것도 Ctrl + P를 눌렀을 경우만 됩니다.