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.