.each()는 Jquery 객체수만큼 for문과 같이 반복 하는 것

-> this함수를 사용하면 현재 콜백되고 있는 함수를 호출할 수 있음.


ex)


<ul>

<li>one</li>

<li>two</li>

</ul>


---------------------

$('li').each(function(index){

alert( index + ':' + $(this).text() );

});


------결과 ----------


0:one

1:two


이렇게 나옴.


최근 이걸 이용한 전자정부프레임워크 확장자 유효성 검사



/* 파일확장자 유효성 체크 */

var returnVal = 0;

var alertMsg = "";

  $("#egovComFileList div").each(function(idx){

var divHtml = $(this).html();

var tmpStr = new RegExp();

tmpStr = /[<][^>]*[>]/gi;

divHtml = divHtml.replace(tmpStr,"");

fileCheck = divHtml.slice(divHtml.indexOf(".") + 1).toLowerCase();

if(

    fileCheck != "txt" && fileCheck != "jpg" && fileCheck != "docx" && fileCheck != "png"

       && fileCheck != "doc" && fileCheck != "bmp" && fileCheck != "gif"  && fileCheck != "pptx" 

       && fileCheck != "xls" && fileCheck != "hwp" && fileCheck != "pdf"  && fileCheck != "wmv"

       && fileCheck != "ppt" && fileCheck != "zip" && fileCheck != "ai"   && fileCheck != "xlsx"

       && fileCheck != "jpeg"

){ //확장자를 확인합니다.

returnVal++;

alertMsg = (idx+1)+"번째 파일의 ["+fileCheck + '] 확장자는 등록할 수 없는 확장자 입니다.';

return false;

}

  });

if( returnVal > 0 ){

alert( alertMsg );

return false;

}

+ Recent posts