input input box propertychange

Original: https://www.cnblogs.com/yuanyanbk/p/8269968.html

Do a search function, they often encounter the demand input box checked, the most common is Instant Search, a good summary of what today.

Instant program search:

(1) change event trigger event must meet two conditions:

  a) the current object property changes, and by keyboard or mouse events fired (script trigger is invalid)
  b) the current object loses focus (onblur)
 
 (2) keypress Well, okay. . . . . Is the ability to listen for keyboard events, mouse copy paste operation he was powerless to catch the foot. . . . .
 
 (3) propertychange (ie) and input events
 
input is the standard browser event, generally used in the input element, occurs when the input's value will change, either keyboard or mouse input pasting changes can be timely to monitor changes

propertychange, as long as the current object property changes.

Here we use jquery to achieve the effects equivalent to the input placeholder for this property

html

?
1
2
3
4
< div class="enterprise-list">
     < label >银行卡号:</ label >
     < input type="text"  placeholder="请输入16或19位银行卡号" class="enterprise-inp" id="cartInput">
</ div >

 

js

?
1
2
3
4
5
6
7
8
9
< script >
     $(function () {
         $("#cartInput").bind('input propertychange',function () {
             var text = $("#cartInput").val();
             text = text.replace(/[^\d]/g,'');
             console.log(text)
         })
     })
</ script >

  

 

With vue write, real-time method can be:

?
1
< input type="text" v-model="bankcard" class="enterprise-inp" v-on:input="cartInput">

  

?
1
2
3
4
cartInput:function () {
                 this.bankcard=this.bankcard.replace(/[^\d]/g,'');
                 console.log(this.bankcard)
             },

  

Do a search function, they often encounter the demand input box checked, the most common is Instant Search, a good summary of what today.

Instant program search:

(1) change event trigger event must meet two conditions:

  a) the current object property changes, and by keyboard or mouse events fired (script trigger is invalid)
  b) the current object loses focus (onblur)
 
 (2) keypress Well, okay. . . . . Is the ability to listen for keyboard events, mouse copy paste operation he was powerless to catch the foot. . . . .
 
 (3) propertychange (ie) and input events
 
input is the standard browser event, generally used in the input element, occurs when the input's value will change, either keyboard or mouse input pasting changes can be timely to monitor changes

propertychange, as long as the current object property changes.

Here we use jquery to achieve the effects equivalent to the input placeholder for this property

html

?
1
2
3
4
< div class="enterprise-list">
     < label >银行卡号:</ label >
     < input type="text"  placeholder="请输入16或19位银行卡号" class="enterprise-inp" id="cartInput">
</ div >

 

js

?
1
2
3
4
5
6
7
8
9
< script >
     $(function () {
         $("#cartInput").bind('input propertychange',function () {
             var text = $("#cartInput").val();
             text = text.replace(/[^\d]/g,'');
             console.log(text)
         })
     })
</ script >

  

 

With vue write, real-time method can be:

?
1
< input type="text" v-model="bankcard" class="enterprise-inp" v-on:input="cartInput">

  

?
1
2
3
4
cartInput:function () {
                 this.bankcard=this.bankcard.replace(/[^\d]/g,'');
                 console.log(this.bankcard)
             },

  

Guess you like

Origin www.cnblogs.com/showcase/p/11532677.html