기본 콘텐츠로 건너뛰기

라벨이 JavaScript인 게시물 표시

jQuery input태그 공백제거

 제이쿼리를 사용하여 input 태그의 공백을 제거하기 < form :input path ="email" title =" 이메일 주소 " class ="emailCheck" maxlength ="50" /> $ ( '. emailCheck' ). focusout ( function (){ var a = $ ( '. emailCheck' ). val (). replace ( / /gi , '' ) ; $ ( '. emailCheck' ). val (a) ; }) ;

jQuery 체크박스 데이터 관리하기

  jQuery  checkbox   컨트롤   1.   checkbox   checked   여부 : id 인 경우 : $('input: checkbox [ id =" checkbox _id "]'). is (": checked ") ==  true name 인 경우 : $('input: checkbox [ name =" checkbox _name "]'). is (": checked ") ==   true   =>   $('input[ id =" checkbox _id "]') + 옵션 형태로 작성 해도 문제는 없다 Ex)  $('input[ name =" checkbox _name "]'). is (": checked ")   2.  checkbox   전체 갯수 : $('input: checkbox [ name =" checkbox _name "]'). length 3.   checkbox   선택된 갯수 :  $('input: checkbox [ name =" checkbox _name "]: checked '). length * 2,3번은  name  인 경우에만 가능   4.  checkbox   전체 순회 하며 처리(동일한  name 으로 여래개인 경우 전체를 컨트롤 할 수 있다.)  $('input: checkbox [ name =" checkbox _name " ]'). each ( function () {        this . checked   =  true ; // checked   처리        if ( this . checked ){ // checked   처리된 항목의 값             alert( this . value ) ;       

select 박스 활용

 jQuery로 선택된 값 읽기 $("#selectBox option:selected").val(); $("#select_box > option:selected").val() $("select[name=name]").val(); jQuery로 선택된 내용 읽기 $("#selectBox option:selected").text(); 선택된 위치 var index = $("#test option").index($("#test option:selected")); Add options to the end of a select $("#selectBox").append("<option value='1'>Apples</option>"); $("#selectBox").append("<option value='2'>After Apples</option>"); Add options to the start of a select $("#selectBox").prepend("<option value='0'>Before Apples</option>"); Replace all the options with new options $("#selectBox") .html("<option value='1'>oranges</option><option value='2'>Oranges</option>"); Replace items at a certain index $("#selectBox option:eq(1)") .replaceWith("<