하나의 변수에 여러개의 값 넣기! 채택완료
안녕하세요!! 고수님들 질문이 있습니다!
하나의 변수에 여러개의 값을 넣으려고 하는데 안 먹힙니다ㅠㅠ
아래처럼 페이지 링크를 가져와서 cate_no=42, cate_no=43 이 링크에 들어있을 경우 클래스를 넣는 방법을 해봤는데, cate_no=42, cate_no=43 따로 적으면 먹는데 동시에 적고 싶습니다ㅠㅠ 방법좀 알려주세요!!
var link = document.location.href;
var cate_no42 = ["cate_no=42","cate_no=43"];
if(link.indexOf(cate_no42) != -1) {
$('.list03_tab li:first-child').addClass('selected');
}
else {
$('.list03_tab li:first-child').removeClass('selected');
}
if(link.indexOf(cate_no43) != -1) {
$('.list03_tab li:first-child').addClass('selected');
}
else {
$('.list03_tab li:first-child').removeClass('selected');
}
답변 1개
if(link.indexOf(cate_no42) != -1 || link.indexOf(cate_no43) != -1) {
$('.list03_tab li:first-child').addClass('selected');
}
else {
$('.list03_tab li:first-child').removeClass('selected');
}
답변에 대한 댓글 2개
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
혹시 var 변수도 값을 합치고 싶은데 방법 알 수 있을까요?!! 두가지를 가능한 짧게 만들고 싶습니다..
var cate_no42 = "cate_no=42";
var cate_no43 = "cate_no=43";