欧美日韩国产一区二区|qovd片|小明个人发布看看|小浪货你夹真紧水又多|老头把我添高潮了A片故|99热久久精品国产一区二区|久久久春色AV

兼容Firefox和IE的onpropertychange事件oninput

在文本框輸入數(shù)據(jù)的時(shí)候,當(dāng)鍵盤按下并放開的時(shí)候可以使用onkeyup來(lái)檢測(cè)事件,onpropertychange能夠捕獲每次改變,而onchange需要執(zhí)行某個(gè)事件才可以捕獲 。可是有的時(shí)候我們輸入數(shù)據(jù)是采用粘貼的方式而不是鍵盤輸入 , 這就需要實(shí)時(shí)檢測(cè)文本框狀態(tài)的改變 。
onpropertychange不被firefox所支持,如果想在firefox下正常使用,需要用oninput屬性,且需要用addEventListener來(lái)注冊(cè)事件 。
//當(dāng)狀態(tài)改變的時(shí)候執(zhí)行的函數(shù) function handle() {document.getElementById(’msg’).innerHTML=’輸入的文字長(zhǎng)度為:’ document.getElementById(’txt’).value.length; } //firefox下檢測(cè)狀態(tài)改變只能用oninput,且需要用addEventListener來(lái)注冊(cè)事件 。if(/msie/i.test(navigator.userAgent))//ie瀏覽器 {document.getElementById(’txt’).onpropertychange=handle } else {//非ie瀏覽器 , 比如Firefox document.getElementById(’txt’).addEventListener("input",handle,false); }
[Ctrl A 全選 注:如需引入外部Js需刷新才能執(zhí)行]
例子:
復(fù)制代碼 代碼如下:
html
body
divoninput測(cè)試/div
divid="testdiv"inputid=’tx1’name="tx1"value=""http://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事件方法 。您可能感興趣的文章:輸入框的字?jǐn)?shù)時(shí)時(shí)統(tǒng)計(jì)—關(guān)于 onpropertychange 和 oninput 使用js監(jiān)聽輸入框值的即時(shí)變化onpropertychange、oninputjavascript開發(fā)中使用onpropertychange,oninput事件解決onchange事件的不足asp.net關(guān)于onpropertychange和oninput事件實(shí)現(xiàn)代碼js propertychange和oninput事件

相關(guān)經(jīng)驗(yàn)推薦