html change 事件

The change event is fired for <input><select>, and <textarea> elements when a change to the element‘s value is committed by the user. Unlike the inputevent, the change event is not necessarily fired for each change to an element‘s value.

事件在元素input,select,textarea的内容由用户改变的时候触发,并且不像input事件每一次的改变都触发。

Description

Depending on the kind of form element being changed and the way the user interacts with the element, the change event fires at a different moment:

  • When the element is activated (by clicking or using the keyboard) for <input type="radio"> and <input type="checkbox">;
  • When the user commits the change explicitly (e.g. by selecting a value from a <select>‘s dropdown with a mouse click, by selecting a date from a date picker for <input type="date">, by selecting a file in the file picker for <input type="file">, etc.);
  • When the element loses focus after its value was changed, but not commited (e.g. after editing the value of <textarea> or <input type="text">).

Different browsers do not always agree whether a change event should be fired for certain types of interaction. For example, keyboard navigation in <select>elements never fires a change event in Gecko until the user hits Enter or switches the focus away from the <select> (see bug 126379).

描述

事件触发依赖于元素类型,触发方式以及触发不同时刻,如下所示

  • 对于<input type=‘radio‘>和<input type="checkbox">,元素激活时触发(通过点击或者键盘)
  • 用户明确提交更改(例如,鼠标点击选取select,从 <input type="date">选取日期,从<input type="file">选取文件)
  • 元素失去焦点时内容以改变,但并未提交(例如 <textarea> 或者 <input type="text">)也会触发、

不同的游览器不保证特定类型的交互触发change事件。例如,在Gecko,除非用户点击enter或者从<select>移去焦点,通过键盘选取select将不会触发change事件。


引用:https://developer.mozilla.org/en-US/docs/Web/Events/change

**

怪不得很多change事件和预想的不一样。

时间: 2024-07-30 10:45:04

html change 事件的相关文章

js设置下拉框选中后change事件无效解决

下拉框部分代码: <select id="bigType"> <option value="">请选择</option> <option value="1">xiamen</option> <option value="2">beijing</option> </select> <select id="smallTy

easyui给select控件绑定change事件

一般的做法是使用jQuery来绑定,例如: $("#id").change(function(){ alert("change事件绑定"); }); 当给select加上class="easyui-combobox"这样的样式后,上面的绑定方式失效不相应,正确的方式如下: <select required="false" class="easyui combobox"name="city&q

以input=file方式,获取文件时,在IE下8无法通过某个按钮click事件间接触发input=file的change事件

最近在项目中遇到了许多上传问题,公司内部的组件,通过form上传,需要使用input=file触发选择文件, 因为input=file在各个浏览器中显示的样式是不同的,谷歌,火狐,IE都有所不同,而且不太美观,所以为了解决 这一个问题,一开始采用了隐藏input=file 然后通过一个显示的button间接触发input=file的click事件如下 <input type="file" id="upload" style="display:none

Dynamic CRM 2013学习笔记(二十八)用JS动态设置字段的change事件、必填以及可见

我们知道通过界面设置字段的change事件,是否是必填,是否可见非常容易.但有时我们需要动态地根据某些条件来设置,这时有需要通过js来动态地控制了. 下面分别介绍如何用js来动态设置.   一.动态设置字段的change事件 // form on load event function onLoad() { init();   pageAttr.delivery_from.addOnChange(deliveryFromChange); pageAttr.type.addOnChange(typ

复选框 省市区 联动(监听input的change事件)

需求:省市区三级包含复选框按钮以及文字描述.点击文字显示对应的下级地区,点击复选框选择对应的下级区域勾选. 分析:监听input的change事件当点击复选框省  选择对应的第一个市区,同时默认选中第三级区域的第一个.同理监听span或者label(因为label与input的搭配使用) 辅助:后台提供省市区的数据: 两种方式: A:后台直接给dom结构(后台写好基本构架,前段自己在后台code填写需要的dom,class,方便前端开发) B:后台直接给前段一个json数据,前段自己遍历.(和后

file控件change事件触发问题

最近,项目中需要用到一个图片上传的功能,我用的file控件来选取图片文件,然后利用js读取文件来预览图片,最后再根据用户的操作来决定是否上传文件. 其中碰到了一个奇怪的问题:在选取完第一张图片,并上传后,再选取第二张图片的时候,并没有触发file的change事件. 问了下度娘,各种解决方案很多: 1)有的说要使用live来注册事件,如可以写成$('#fileID').live('change,function(){//do something}); 2)有的说要用replaceWith把原来的

EXTJS项目实战经验总结一:日期组件的change事件:

1  依据选择的日期,加载相应的列表数据,如图:   开发说明    1 开发思路: 在日期值变化的事件中获得选择后的日期值,传给后台,然后从后台加载相应的数据 2 问题:在查看extjs2.2 的api的官方说明文档,文档对datefield组件的change事件说明如下: change : ( Ext.form.Field this, Mixed newValue, Mixed oldValue )       Fires just before the field blurs if the

JQuery触发radio或checkbox的change事件

在JQuery中,当给radio或checkbox添加一个change事件时,如果它的值发生变化就会触发change事件;本文将详细介绍如何利用JQuery触发Checkbox的change事件需要了解的朋友可以参考下 早上要做一功能,checkbox被选中时,显示隐藏的层,取消选中时,再隐藏选中的层. 初始代码如下: 复制代码代码如下: $(function(){ $("#ischange").change(function() { alert("checked"

radio的change事件

radio的change事件 <script type="text/javascript"> $(document).ready(function() { $(".radioItem").change(function() { var $selectedvalue = $("input[name='rl$tt']:checked").val(); // alert($selectedvalue); if ($selectedvalue

input输入框的change事件

input输入框的change事件,要在input失去焦点的时候才会触发 $('input[name=myInput]').change(function() { ... }); 在输入框内容变化的时候不会触发change,当鼠标在其他地方点一下才会触发 用下面的方法会生效,input $("#input_id").on('input',function(e){ alert('Changed!') });