# 表单
# text
账号: <input type="text" name="username"><br/>
密码: <input type="password" name="password"><br/>
# file
文件: <input type="file" name="file">
# radio
<input type="radio" name="sex" value="male">Male<br/>
<input type="radio" name="sex" value="female">Female
# checkbox
<input type="checkbox" name="vehicle" value="Bike">I have a bike<br/>
<input type="checkbox" name="vehicle" value="Car">I have a car
# select
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat" selected>Fiat</option>
<option value="audi">Audi</option>
</select>
# textarea
<textarea rows="10" cols="30">
我是一个文本框。
</textarea>
# button
<input type="button" onclick="alert('你好,世界!')" value="点我!">
<input type="submit" value="提交!">
<button type="button" onclick="alert('你好,世界!')">点我!</button>
<button type="submit">提交!</button>
# clear
document.getElementById("myForm").reset();
$("#myForm").find('input[type=text],select,input[type=hidden]').each(function() {
$(this).val('');
});
$(':input', '#myForm').each(function () {
var type = this.type;
var tag = this.tagName.toLowerCase();
if (type == 'text' || type == 'password' || tag == 'textarea' || type == "hidden") {
this.value = "";
} else if (type == 'checkbox' || type == 'radio') {
this.checked = false;
} else if (tag == 'select') {
this.selectedIndex = -1;
}
});
# readonly 和 disabled
| 作用域 | 表单提交 | |
|---|---|---|
| readonly | text/password/textarea | 传递 |
| disabled | 所有表单元素 | 不传递 |
表格 →