最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jQuery/JS監(jiān)聽(tīng)input輸入框值變化實(shí)例

 更新時(shí)間:2019年10月17日 15:50:50   作者:虛無(wú)境-  
在本篇文章里小編給大家整理的是一篇關(guān)于jQuery/JS監(jiān)聽(tīng)input輸入框值變化實(shí)例內(nèi)容,需要的朋友們學(xué)習(xí)下。

input事件:

onchange:

1、要在 input 失去焦點(diǎn)的時(shí)候才會(huì)觸發(fā);

2、在輸入框內(nèi)容變化的時(shí)候不會(huì)觸發(fā)change,當(dāng)鼠標(biāo)在其他地方點(diǎn)一下才會(huì)觸發(fā);

3、onchange event 所有主要瀏覽器都支持;

4、onchange 屬性可以使用于:<input>, <select>, 和 <textarea>。

<script>
  function change(){
    var x=document.getElementById("password");
    x.value=x.value.toUpperCase();<br data-filtered="filtered">    console.log("出發(fā)了")
   }
</script>
</head>
<body>
 
  輸入你的密碼: <input type="text" id="password" onchange="change()">
 
</body>

oninput:

1、在用戶輸入時(shí)觸發(fā),它是在元素值發(fā)生變化時(shí)立即觸發(fā);

2、該事件在 <input> 或 <textarea> 元素的值發(fā)生改變時(shí)觸發(fā)。

3、缺陷:從腳本中修改值不會(huì)觸發(fā)事件。從瀏覽器下拉提示框里選取值時(shí)不會(huì)觸發(fā)。IE9 以下不支持,所以IE9以下可用onpropertychange 事件代替。

JS: <input type="text" id="password" oninput="change()">
jQuery: $("#password").on('input propertychange', change);

onpropertychange:

1、會(huì)實(shí)時(shí)觸發(fā),會(huì)在元素的屬性改變時(shí)就觸發(fā)事件。當(dāng)元素disable=true時(shí)不會(huì)觸發(fā)

2、缺陷:只在IE 下支持,其他瀏覽器不支持,用oninput來(lái)解決。

<input type="text" id="password" oninput="onpropertychange()">

jQuery:

<!DOCTYPE html> 
<html> 
  <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title>RunJS</title> 
  <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  </head> 
  <body> 
    <input type="text" id="password" autoComplete='off'> 
   <script type="text/javascript">
$(function(){ 
  $('#password').bind('input propertychange', function() { <br data-filtered="filtered">     console.log('在實(shí)時(shí)觸發(fā)!??!')
    $('#result').html($(this).val().length); <br data-filtered="filtered">     $(this).val().length != 0 ? $("#login").css("background-color", "#086AC1") : $("#login").css("background-color", "#529DE0")
  });
})  
    </script>
  </body> 
</html>  

JavaScript;

<script type="text/javascript">
  // Firefox, Google Chrome, Opera, Safari, Internet Explorer from version 9
    function OnInput (event) {
      alert ("The new content: " + event.target.value);
    }
  // Internet Explorer
    function OnPropChanged (event) {
      if (event.propertyName.toLowerCase () == "value") {
        alert ("The new content: " + event.srcElement.value);
      }
    }
</script>
 
<input type="text" oninput="OnInput (event)" onpropertychange="OnPropChanged (event)" value="Text field" />

以上就是本次介紹的全部相關(guān)知識(shí)點(diǎn),感謝大家的學(xué)習(xí)和對(duì)腳本之家的支持。

相關(guān)文章

最新評(píng)論

文化| 麻栗坡县| 阿城市| 楚雄市| 南宫市| 瑞丽市| 内黄县| 中宁县| 海伦市| 南开区| 巨鹿县| 辽阳市| 安图县| 晋江市| 大悟县| 平凉市| 通海县| 防城港市| 东阳市| 甘德县| 武威市| 眉山市| 偃师市| 新闻| 安化县| 大田县| 娄烦县| 伽师县| 大埔区| 连城县| 新闻| 宜兴市| 遵化市| 巴东县| 和龙市| 图木舒克市| 定远县| 新竹县| 扎赉特旗| 博客| 齐河县|