<form action="#" method="get"> <input type="text" name="user"> <input type="password" name="pwd"> <button type="submit">提交</button> <button type="reset">重置</button> </form>
1. form表单的提交事件
$('form').submit(function (event) { console.log('form表单提交了......') // 终止默认事件的传递 event.preventDefault() })
2. form表单的重置事件
$('button[type="reset"]').click(function (event) { result = confirm('你确定要清空数据吗?') if(result == false){ // 中断默认事件 event.preventDefault() } })
3. 当输入框内容发生改变时, 输入框失去焦点的时候, 触发该事件
$('input[name="user"]').change(function () { if ($(this).val().length < 6){ $(this).css('border','2px solid red') }else{ $(this).css('border','2px solid black') } })
4. blur( ) 无论输入框内容是否更改, 只要失去焦点就会触发事件
$('input[name="pwd"]').blur(function () { console.log('///////') })