자바스크립트 explorer 호환
본문
안녕하세요.
자바스크립트 왕초보로 학습자로서 며칠을 고생해 코드를 완성했다고 생각하고 좋아했는데.
Internet Explorer 에서 안되네요...ㅠㅠ 절망감..
jQuery(function($){
function monthYearShow(){
$(".only_one").each(function() {
this.remove();
});
var entYear_arr=[];
$('input[name="ent_date_each"]').each(function(){entYear_arr.push($(this).val().slice(0,4))});
var entMonth_arr=[];
$('input[name="ent_date_each"]').each(function(){entMonth_arr.push($(this).val().slice(5,7).replace(/(^0+)/, ""))});
//console.log(entYear_arr);
var today = new Date();
for(var i=0; i<entYear_arr.length; i++){
if( i==0 ){
if( entYear_arr[0] != today.getFullYear() ){
$(".ent_posts div").eq(i).before("<span class='only_one' style='background:yellow;'>"+entYear_arr[i]+"년 </span>");
}
$(".ent_posts div").eq(i).before("<span class='only_one' style='background:yellow;'>"+entMonth_arr[i]+"월</span>");
}
else{
if( entMonth_arr[i] != entMonth_arr[i-1] ){
if( entYear_arr[i] != entYear_arr[i-1] ){
$(".ent_posts div").eq(i).before("<span class='only_one' style='background:yellow;'>"+entYear_arr[i]+"년 </span>");
}
$(".ent_posts div").eq(i).before("<span class='only_one' style='background:yellow;'>"+entMonth_arr[i]+"월</span>");
}
}
}
}
$(window).load(monthYearShow);
});
일단 remove()가 작동 안되네요. 그리고 다른 것도 작동 안하는 것 같은데.ㅠ 먼지 모르겠네요. 일단 개발자 창에는 remove만 안된다고 뜨는데,
ajax 시 년월이 추가가 안되는 것을 보면. 다른 것도 안되는 것이 있는 것 같은데,
조언을 좀 부탁드립니다...ㅠ 절망감이 크네요ㅠ
!-->답변 1
"jQuery(function($){~ });" 이, 문서가 로드될 때 자동으로 실행됩니다.
그래서 monthYearShow 를 만들고 $(window).load() 를 호출하지 않아도 됩니다.
this 보다는 jqeury $(this) 사용을 추천합니다.
생각난 것들만 정리해서, 별로 도움이 되지 않을 수도 있습니다.
jQuery(function($){
$(".only_one").each(function() {
//this.remove();
$(this).remove();
});
var entYear_arr=[];
$('input[name="ent_date_each"]').each(function(){entYear_arr.push($(this).val().slice(0,4))});
var entMonth_arr=[];
$('input[name="ent_date_each"]').each(function(){entMonth_arr.push($(this).val().slice(5,7).replace(/(^0+)/, ""))});
//console.log(entYear_arr);
var today = new Date();
for(var i=0; i<entYear_arr.length; i++){
if( i==0 ){
if( entYear_arr[0] != today.getFullYear() ){
$(".ent_posts div").eq(i).before("<span class='only_one' style='background:yellow;'>"+entYear_arr[i]+"년 </span>");
}
$(".ent_posts div").eq(i).before("<span class='only_one' style='background:yellow;'>"+entMonth_arr[i]+"월</span>");
}
else{
if( entMonth_arr[i] != entMonth_arr[i-1] ){
if( entYear_arr[i] != entYear_arr[i-1] ){
$(".ent_posts div").eq(i).before("<span class='only_one' style='background:yellow;'>"+entYear_arr[i]+"년 </span>");
}
$(".ent_posts div").eq(i).before("<span class='only_one' style='background:yellow;'>"+entMonth_arr[i]+"월</span>");
}
}
}
//$(window).load(monthYearShow);
});
답변을 작성하시기 전에 로그인 해주세요.