양식의 다양한 요소와 유형을 알고 싶습니다.jquery - 양식 필드 유형을 식별하는 방법
내 HTML은 다음과 같습니다
<form action="save_form" method="post" id="newform" name="newform">
<div class="form_description">
<h2 class="editable">Form title. Click here to edit</h2>
<p class="editable">This is your form description. Click here to edit.</p>
</div>
<ul id="form_body" class="ui-sortable">
<li id="field1" class="">
<a href="#" onclick="return false;" class="hover">
<label class="editable" for="field1">Text1</label>
<input type="text" name="field1" value="">
</a>
</li>
<li id="field2" class="">
<a href="#" onclick="return false;" class="hover">
<label class="editable" for="field2">Paragraph2</label>
<div><textarea cols="" rows="" class="textarea" name="field2"></textarea></div>
</a>
</li>
<li id="radiogroup3" class="">
<a href="#" onclick="return false;" class="hover">
<label class="editable" for="radiogroup3">Label3</label>
<input type="radio" id="radiogroup31" name="radiogroup3" value="1" class="element radio">
<label class="choice editable" for="radiogroup31">option1</label>
<input type="radio" id="radiogroup32" name="radiogroup3" value="2" class="element radio">
<label class="choice editable" for="radiogroup32">option2</label>
<input type="radio" id="radiogroup33" name="radiogroup3" value="3" class="element radio">
<label class="choice editable" for="radiogroup33">option3</label>
</a>
</li></ul>
</form>
나는 아래의 기능을 함께했다하지만 불을 지르고 콘솔이 올바른 값을 보여줍니다에도 불구하고 (정의되지 않은) 값을 this.type 반환하지 않습니다.
attr ('type')은 텍스트 영역과 레이블에서 작동하지 않으므로 사용할 수 없습니다.
test = $('#newform').map(function(){ return $.makeArray(this.elements); });
if (test.length != 0) {
test.each(function(){
console.log($(this).type);
});
}
레이블, 텍스트 영역 및 라디오 버튼을 포함하여 양식의 모든 요소를 가져올 수있는 방법이 있습니까?
당신이'만을 원하는 마십시오
type
속성 사용을 얻을 $ ('입력, 텍스트 영역')2)를 사용할 수 있습니다 input ','label','textarea' 엘레멘트,'form' 엘레멘트의 모든 자식들 (예를 들어'li' 또는'a' 엘레멘트 포함)? –
'$ (this) .type'은 정의되지 않았기 때문에'this.type'을 사용해야합니다. – Paulpro
제임스, 나는 레이블, 입력, 텍스트 영역, 라디오 등 모든 형태의 관련 요소를 얻고 싶습니다. 선호하는 순서대로 그들은 – truthSeekr