我的 HTML 表单如下所示
<form id="form1" name="form1" method="post" action="">
number: <input name="formnum" type="text" id="input_1" tabindex="1" size="30" maxlength="30" />
Title:
<select name="title" id="input_2" tabindex="2" >
<option selected="selected" value=""></option>
<option value="Mr." id="option_1 ">Mr.</option>
<option value="Mrs." id="option_2">Mrs.</option>
<option value="Ms." id="option_3">Ms.</option>
<option value="Dr." id="option_4">Dr.</option>
</select>
<label> <input type="radio" name="gender" value="Male" id="input_3" tabindex="3"/>Male </label>
<label> <input type="radio" name="gender" value="Female" id="input_3"/> Female</label>
First Name:
<input name="fname" type="text" id="input_5" tabindex="4" value="" size="30" maxlength="30" />
Last Name:
<input name="lname" type="text" id="input_6" tabindex="5" value="" size="30" maxlength="30" />
Address:
<input name="address" type="text" id="input_7" tabindex="6" value="" size="30" maxlength="30" />
<input type="submit" name="Submit" value="Submit" tabindex="16" />
<input type="reset" name="Submit2" value="Reset" tabindex="17" />
</form>
我想按照它们在浏览器中出现的顺序列出表单中的所有输入元素$(document).ready()
。input
我在 jQuery 中编写了以下语句,以按照它们在浏览器中出现的顺序列出表单中的元素:
var textboxes = $("#form1 :input")
- 但是这个语句只给出了带有标签的元素列表,
input
即所有的文本框、单选按钮和提交按钮。 - 它不包括给定列表中的选择框、文本区域。
这是我的 jQuery 代码:
$(document).ready(function(){
var textboxes = $("#form1 :input"), //gets all the textboxes
images = $("img.classforimg"); //gets all the images
images.hide(); //hide all of them except the first one
alert(textboxes.length);
textboxes.each(function (i){
var j = i;
$(this).focus(function (){
images.hide(); //hide all of them except the first one
images.eq(0).show();
images.eq(j).show();
});
});
**Here Jquery code for form validation**
**Here Jquery code of Custom validation methods**
});
问题:
- 如何按照它们在浏览器中出现的顺序获取表单中所有元素的列表,
$(document).ready()
包括所有输入文本框、单选按钮组、复选框、选择框、文本区域和按钮? - 上述语句将上述形式的单选按钮视为单个单选按钮,而不将它们视为一个组,但实际上上述单选按钮属于同一组。那么如何解决这些问题呢?
请朋友们帮帮我!谢谢你!