본문 바로가기

728x90
반응형

JS/JQuery

(13)
[JS] javascript 비디오 재생 여부 확인 방법 function video_play_yn(id){ let msg = false; let video = $('#'+id).get(0); if (video.paused) { msg = true; // 비디오정지 } else { msg = false; // 비디오 재생중 } return msg; } console.log("v_1");
[jquery] input name값 배열에 넣기 $(document).ready(function() { let list = new Array(); $("input[name=name[]]").each(function(index, item){ list.push($(item).val()); }); console.log(list); });
[jquery] 스마트폰 스크롤 감지 let ts; $('#scroll_event').bind('touchstart', function(e){ e.stopPropagation(); ts = e.originalEvent.touches[0].clientY; }); $('#scroll_event').bind('touchend', function(e){ e.stopPropagation(); var te = e. originalEvent.changedTouches[0].clientY; if(ts > te + 5){ //스크롤 내릴때 } else if(ts < te - 5){ //스크롤 올릴때 } });
[jquery] PC Mobile 체크 function isMobile(){ let filter = "win16|win32|win64|mac"; let mc = ""; if(navigator.platform){ if(0 > filter.indexOf(navigator.platform.toLowerCase())){ mc = true; }else{ mc = false; } } return mc; } if(!isMobile()){ console.log('pc'); }else{ console.log('mobile'); }
[jquery] mousewheel 스크롤이 위로올라가는중인지 내려가는지 이벤트 감지 $(document).on('mousewheel', ".scroll_area", function(e){ let wheel = e.originalEvent.wheelDelta; if(wheel>0){ //스크롤 올릴때 } else { //스크롤 내릴때 } });
[jquery] JSON 문자열을 배열로 변환 jQuery.parseJSON let arr = '["a.png","b.jpg","c.png"]'; arr = jQuery.parseJSON(arr); console.log(arr[0]); 결과 : a.png
[JQuery] checkbox 체크된 값 가져오기 $('input:radio[name="radio"]:checked').val() /* radio */ $('input:checkbox[name="checkbox"]:checked').val() /* checkbox */ $("input:checkbox[id='ID']").is(":checked") == true : false /* by ID */ $("input:checkbox[name='NAME']").is(":checked") == true : false /* by NAME */ $("input:checkbox[id='ID']").prop("checked", true); /* by ID */ $("input:checkbox[name='NAME']").prop("checked", false); /* b..
submit 엔터키 막기 $('input[type="text"]').keydown(function() { if (event.keyCode === 13) { event.preventDefault(); }; });

728x90
반응형