2010-04-11 6 views
4

지금까지 기본 jquery 선택기와 함수 만 사용했습니다. 하지만이 clear form function보고 있는데 숨겨진 된 입력을 제거하고 지우기 입력을 readinly 지울 수 있도록 추가하는 방법을 알아낼 수 없습니다.다음을 사용하여 읽기 전용 필드를 제외하는 방법 : input in jquery?

아무도 도와 드릴 수 있습니까? 덕분에 . 요소가 선언에 readonly 속성이있는 경우

function clearForm(form) { 
    // iterate over all of the inputs for the form 
    // element that was passed in 
    $(':input', form).each(function() { 
var type = this.type; 
var tag = this.tagName.toLowerCase(); // normalize case 
// it's ok to reset the value attr of text inputs, 
// password inputs, and textareas 
if (type == 'text' || type == 'password' || tag == 'textarea') 
    this.value = ""; 
// checkboxes and radios need to have their checked state cleared 
// but should *not* have their 'value' changed 
else if (type == 'checkbox' || type == 'radio') 
    this.checked = false; 
// select elements need to have their 'selectedIndex' property set to -1 
// (this works for both single and multiple select elements) 
else if (tag == 'select') 
    this.selectedIndex = -1; 
    }); 
}; 

답변

13

, 당신은 jQuery’s :not() selector 사용할 수 있습니다

$(':input', form).each(function() { 
    if (this.readOnly) return; 
    // … 
}); 
+0

하지만 어떻게 그 기능에 넣으시겠습니까? – melaos

+0

달콤한, 그게 내가 필요한거야. – melaos

+0

그래서 anwer를 올바른 것으로 표시하십시오. –

1
<script type="text/javascript" language="JavaScript"> 
    jQuery(document).ready(function(){ 
     try { 
      var t = jQuery("input[type=text]").not("[readonly]").focus(function(){ 
       jQuery(this).blur(); 
      }); 
      alert(t.length); 
     } 
     catch(error){ 
      alert("error :" + error); 
     } 
    }); 
</script> 
:

$(':input:not([readonly])', form) 

그렇지 않으면이 같은 뭔가 읽기 전용 요소를 필터링

관련 문제