Iefans,靠谱的软件下载站

首页 最新文章 最新安卓 最新苹果 浏览器 IE教程 在线图片编辑 最新软件 最新游戏

当前位置: IEfans / IE专区 / IE动态/ 兼容Firefox和IE的onpropertychange事件oninput

兼容Firefox和IE的onpropertychange事件oninput

编辑:秩名2023-06-28 19:30:02

在文本框输入数据的时候,当键盘按下并放开的时候可以使用onkeyup来检测事件,onpropertychange能够捕获每次改变,而onchange需要执行某个事件才可以捕获。可是有的时候我们输入数据是采用粘贴的方式而不是键盘输入,这就需要实时检测文本框状态的改变。
onpropertychange不被firefox所支持,如果想在firefox下正常使用,需要用oninput属性,且需要用addEventListener来注册事件。

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
例子:
复制代码 代码如下:
html
body
divoninput测试/div
divid="testdiv"inputid='tx1'name="tx1"value=""//div
/body
/html
scriptlanguage="JavaScript"
!--
functiongetOs(){//判断浏览器类型
varOsObject="";
if(navigator.userAgent.indexOf("MSIE")0){
return"MSIE";
}
if(isFirefox=navigator.userAgent.indexOf("Firefox")0){
return"Firefox";
}
if(isSafari=navigator.userAgent.indexOf("Safari")0){
return"Safari";
}
if(isCamino=navigator.userAgent.indexOf("Camino")0){
return"Camino";
}
if(isMozilla=navigator.userAgent.indexOf("Gecko/")0){
return"Gecko";
}

}

if(navigator.userAgent.indexOf("MSIE")0){
document.getElementById('tx1').attachEvent("onpropertychange",txChange);
}elseif(navigator.userAgent.indexOf("Firefox")0){
document.getElementById('tx1').addEventListener("input",txChange2,false);
}
functiontxChange(){
alert("testie");
}
functiontxChange2(){
alert("testfirefox");
}
/script

以上就是兼容Firefox的onpropertychange事件方法。

您可能感兴趣的文章:

  • 输入框的字数时时统计—关于 onpropertychange 和 oninput 使用
  • js监听输入框值的即时变化onpropertychange、oninput
  • javascript开发中使用onpropertychange,oninput事件解决onchange事件的不足
  • asp.net关于onpropertychange和oninput事件实现代码
  • js propertychange和oninput事件
返回旧版Copyright © 1998-2023 www.iefans.net All Rights Reserved 沪ICP备17019769号-18 意见反馈