Onpropertychange in IE8

Source: Internet
Author: User
Code

  1   <!  Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"  >  
2   < Html Xmlns = "Http://www.w3.org/1999/xhtml" >
3   < Head >
4 < Title > Untitled page </ Title >
5 < Script Type = "Text/JavaScript" >
6 Function Test ()
7 {
8 TXT. Value = ' Helloworld ' ;
9 }
10 Function Change (){
11 Document. getelementbyid ( ' Show ' ). Innerhtml = TXT. value;
12 }
13 </ Script >
14   </ Head >
15   < Body >
16   < Span ID = "Show" > </ Span >
17 < Input Name = "TXT" Type = "Text" Value = "123" Onpropertychange = "Change ()" />
18 < Button Onclick = "Test ()" > Test </ Button >
19 </ Body >
20 </ Html >

In principle, modifying the content in the input box should trigger the onpropertychange event, but there will be a problem in IE8:

Click the button as shown in the following figure (see ):

Delete D, but the onpropertychange event is not triggered (SEE)

Then delete L. The onpropertychange event is triggered (SEE)

There is no such problem in IE7. Is there a solution?

Solution 1:

Code

  1   <!  Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"  >   
2 < Html Xmlns = "Http://www.w3.org/1999/xhtml" >
3 < Head > < Title > Untitled page </ Title >
4 < Script Type = "Text/JavaScript" SRC = "Jquery-1.3.2.min.js" > </ Script >
5 < Script Type = "Text/JavaScript" >
6 $ ( Function (){
7 $ ( ' # Txt ' ). BIND ( ' Propertychange ' , Change );
8 });
9 Function Test (){
10 $ ( ' # Txt ' ). Val ( ' Helloworld ' ). Replacewith ( ' <Input id = "TXT" type = "text" value =" ' + $ ( ' # Txt ' ). Val () + ' "/> ' ); // Replace Input
11 $ ( ' # Txt ' ). BIND ( ' Propertychange ' , Change );

13 }
14 Function Change (){
15 $ ( ' # Show ' Pai.html ($ ( ' # Txt ' ). Val ());
16 }
17 </ Script >
18 </ Head >
19 < Body >
20 < Span ID = "Show" > </ Span >
21 < Input ID = "TXT" Name = "TXT" Type = "Text" Value = "123" />
22 < Button Onclick = "Test ()" > Test </ Button >
23 </ Body >
24 </ Html >

Note: during the experiment, an onpropertychange event is triggered after <input> is assigned a value (txt. value = 'helloworld'), and the event becomes invalid,

However, this is only valid once. If you attempt to re-bind the event after the assignment, it is still invalid. Therefore, after the assignment, you can simply replace the input element and re-bind the event.

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.