亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

js監(jiān)聽input輸入框值的實(shí)時(shí)變化實(shí)例

 更新時(shí)間:2017年01月26日 11:35:47   投稿:jingxian  
下面小編就為大家?guī)硪黄猨s監(jiān)聽input輸入框值的實(shí)時(shí)變化實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

1、在元素上同時(shí)綁定 oninput 和onporpertychanger事件

例:

<script type="text/JavaScript">
function aa(e){alert("inputting!!");}
</script>

<input type="text" id="a" oninput="aa(event)" onporpertychange="aa(event)" />

2、使用原生js添加監(jiān)聽事件

<script type="text/javascript">
 $(function(){
if("\v"=="v"){//true為IE瀏覽器,感興趣的同學(xué)可以去搜下,據(jù)說是現(xiàn)有最流行的判斷瀏覽器的方法
document.getElementById("a").attachEvent("onporpertychange",function(e){
console.log("inputting!!");
}
}else{
document.getElementById("a").addEventListener("onporpertychange",function(e){
console.log("inputting!!");
}
}
});
</script>
<input type="text" id="a"/>

3、使用jQuery方法綁定事件

<script type="text/javascript">
 $(function(){
$("#a").bind('input porpertychange',function(){
console.log("e");
});
});
</script>
<input type="text" id="a"/>

在監(jiān)聽到 onpropertychange 事件后,可以使用 event 的 propertyName 屬性來獲取發(fā)生變化的屬性名稱,event.propertyName

實(shí)例1:

<input type="text" oninput=" " onpropertychange="" value="Text field" />

實(shí)例2:

$("#name").bind('input porpertychange',function(){
    var thisTxt=$("#name").val();
    $(this).siblings("p").html(thisTxt)
  })

實(shí)例3:

//手機(jī)號(hào)碼分段顯示
register.phonePropertychange = function() {
  _this = register;
  _input = $(this);
  var v = $(this).val();
  v = v.replace(new RegExp(/ /g),'');
  var v1 = v.slice(0,3);
  var v2 = v.slice(3,7);
  var v3 = v.slice(7,11);
  if(v2==''){
    _input.focus().val(v1);
  }else if(v3==''){
    _input.focus().val(v1+' '+v2);
  }else{
    _input.focus().val(v1+' '+v2+ ' '+v3);
  };
 
  //手機(jī)號(hào)輸入完成字體顏色改變
  if (v.length === 11) {
    if(_this.regexpPhone(v)){
      _input.css('color','#000');
      $('#btnSendCode').addClass('c-26a949');
      _input.blur();;
    }else{
      layer.open({content: '手機(jī)號(hào)碼不正確,請(qǐng)重新輸入',time: 2, end:function(){
        _input.val('');
      }});
    }
  }else{
    _input.css('color','#26a949');
  }
}

//驗(yàn)證手機(jī)號(hào)
register.regexpPhone = function(phone){
  return /^1[3|4|5|7|8]\d{9}$/.test(phone);
}

以上這篇js監(jiān)聽input輸入框值的實(shí)時(shí)變化實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論