본문 바로가기

Local Oriented/jQuery

[모음글] jQuery 로 form validation 요소 제어, input/select/textarea

 

o jQuery Form Validation 세세한 조정이 필요한 것이 아니라면..
  http://mytory.co.kr/archives/195

 

o select

- $('... > option ...') 과 $('... option ...') 차이는..

   만약 select 가 하나 뿐이면 차이 없음, option 앞에서 딱 하나의 element 가 주어지면 차이 없음.

   다만, option 을 갖는 select 가 여럿일 때는 차이가 있음..
- select 태그의 option 조정
  http://ddoong2.com/386
- $('... select > option:selected').val(); 와 $('... select').children('option:selected').val() 은 동일

  $('... optoin :selected') 는 오류, $('... option:selected') 와 같이 붙여서 기술해야 정상
  http://pengs.pe.kr/297

- .text(), .index()
  http://dwebs.co.kr/wordpress/?p=127

  index 는 0, 1, 2, ...

- 브라보, select 바이블 http://blog.daum.net/twinsnow/124

   $('... > option:eq(n)').after('<option value='m'>Text</option') 또는 after 대신에 before, replaceWith, append, prepend

  $('... > option:selected').prevAll.size() prevAll 대신에 nextAll

   $('... > option:first').remove() first 대신 last. 

   $('...').val('valA') valA 로 select, val 대신에 text

   $('... option:eq(n)').attr('selected',true) true 대신에 'selected'




o input radio
- 라디오 버튼이 선택되었는지..? jQuery 는 Ojbect 배열이기에 length() 가 아니고 length 를 사용
  if($('input[name="mode"]:checked').length==0) alert('선택하세요. ');
- <input type="checkbox" class="checks" ... /> 들이 많은데, 몇개 까지만 체크를 받을때 갯수 체크
   $('input.checks:checked').length
- checkbox
   http://blog.nemobynemo.com/98
- if($(':radio[name="radioname"]:checked').val() != 3)
  $("#radioname").attr('checked', false); // 'false' 또는 false 모두 작동하는 듯..
  $(':radio[name="radioname"]').attr('disabled', 'disabled');
   http://pengs.pe.kr/298
- .attr('disabled', 'disabled') 와 .attr('disabled', true); 모두 정상 작동
  http://pengs.pe.kr/299
http://www.texotela.co.uk/blog/
- 다중조건
$('input[type="radio"][checked="checked"]') 라고 하면 될 것같죠..? 안 될걸요, 아마.. ㅎ.ㅎ
$('input[type="radio"][checked=true]') 가능
$('input[type="radio"][checked=false]') 가능
$('input[type="radio"][checked]') 가능 
$('input[type="radio"]:checked') 가능. 이게 가장 깔끔하지 않나 싶어요. :checked 앞에 공백이 있으면 작동하지 않습니다. ^^;



o http://grzegorz.frydrychowicz.net/jquery_toggleformtext/
  input text password, textarea 에 사용예를 표시하는 jQuery 플러그인

jquery.toggleformtext.zip

  http://digitalbush.com/projects/watermark-input-plugin/ 워터마크라고 하는 사람도 있네요. (회색 텍스트)