Test input every time the entry is legitimate encountered Chinese character input is a problem _ form effects

Source: Internet
Author: User
Take a look at the data, test it for a few days and release the results.


Copy Code code as follows:

<input type= "text" value= "xxx" id= "xx" onclick= "this.myprop= ' xx '" >
<script type= "Text/javascript" >
<!--
document.getElementById (' xx '). attachevent (' Onpropertychange ', function (o) {alert (' OK ')});
-->
</script>



Executing the above code, clicking the input box to find also triggers the onpropertychange, and entering a value also triggers the event, which proves that the event is triggered whenever a value of the attribute is modified.





Second, now that we've found this feature, there's a problem: when we sometimes want to perform a function operation when the value of the input box changes, but also modify a custom attribute so that Onpropertychange is triggered two times, this may not be what we want.


Guess, now that you've provided such a property, you should be able to get which property is changed. Try to get the number of parameters and parameter content.





Copy Code code as follows:

<input type= "text" value= "xxx" id= "xx" onclick= "this.myprop= ' xx '" >
<script type= "Text/javascript" >
<!--
document.getElementById (' xx '). attachevent (' onpropertychange '), function () {
alert (arguments.length);
for (Var i=0;i<arguments.length;i++) {
Alert (Arguments[i]);
}
});
-->
</script>



Executing the above code, you will notice that 1 and [object] pop up, which means that the event only passes a parameter to the callback function and is of type object.


So let's try to iterate over this object.





Copy Code code as follows:

<input type= "text" value= "xxx" id= "xx" onclick= "this.myprop= ' xx '" >
<script type= "Text/javascript" >
<!--
document.getElementById (' xx '). attachevent (' onpropertychange '), function (o) {
For (var item in O) {
Alert (item+ ":" +o[item]);
}
});
-->
</script>



To perform, there are many attributes found, but look carefully we may find such a property: PropertyName, I believe everyone can guess the meaning of this attribute. Yes, this is used to get which property has been modified.





Copy Code code as follows:

<input type= "text" value= "xxx" id= "xx" onclick= "this.myprop= ' xx '" >
<script type= "Text/javascript" >
<!--
document.getElementById (' xx '). attachevent (' onpropertychange '), function (o) {
alert (o.propertyname);
});
-->
</script>



Click the text box individually and enter a value, and you'll notice that MyProp and value are popped up respectively.





Back to the question we started, we just have to decide if the value is changed and OK.


Just look at the code:





Copy Code code as follows:

<input type= "text" value= "xxx" id= "xx" onclick= "this.myprop= ' xx '" >
<script type= "Text/javascript" >
<!--
document.getElementById (' xx '). attachevent (' onpropertychange '), function (o) {
if (o.propertyname!= ' value ') return; Not value change does not perform the following action
//....... function processing
});
-->
</script>



Three. Let FF support onpropertychange similar effect





Before making a real-time check of the input box, such as only allow input numbers, user input is the letter, etc., this time the user input value into red, etc. ... Or to textarea text field remaining can enter the character hint, encountered a problem, use onpropertychange in IE very good very normal, but in FF on the effect of birds ~ ~ ~





So on the Internet to find a feasible way ~ ~ Firefox has a Oninput event effect and onpropertychange the same, so at the same time add oninput and onpropertychange problems to solve the birds ~ ~ oo ....





&lt;input type= "text" oninput= "Cgcolor (This)," onpropertychange= "Cgcolor (This)," maxlength= "4" name= "Pt_bankou" id= " Pt_bankou "value=" "/&gt;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.