提交(与数据库交互)
1、onsubmit事件触发,input、button的type为submit或者input的type为image,与服务器交互前发生,监听函数中可做验证等。preventDefault()可以阻止表单提交
2、from.submit(),不需表单中包含提交按钮,执行后马上与服务器交互
重置(恢复默认值)
1、onreset事件,input、button的type为reset,preventDefault()可阻止
表单元素
1、from.elements,attr、index访问列表
2、除<fieldset>外,表单元素共有的属性,disabled、form、name、readonly、type、value、tabIndex
3、共有的事件,blur、change、focus,鼠标、键盘、HTML等事件
input和textarea
1、textbox.select(),选中文本框中所以的文本
2、select事件,选择文本时触发,selectionStart、selectionEnd所选择文本的起始位置和结束位置
3、JS选择文本,textbox.setSelectionRange(start,end),
兼容
function selectText(textbox, startIndex, stopIndex){
if (textbox.setSelectionRange){
textbox.setSelectionRange(startIndex, stopIndex);
} else if (textbox.createTextRange){
var range = textbox.createTextRange();
range.collapse(true);
range.moveStart("character", startIndex);
range.moveEnd("character", stopIndex - startIndex);
range.select();
}
textbox.focus();
}
4、H5验证API,required。<input>、<textarea>、<select>
其他
1、input的size属性是指定最多能显示字符数量,maxlength指定最多能输入的字符数