1 | <head> |
---|
2 | <script src="jquery-1.3.1.js"></script> |
---|
3 | <script> |
---|
4 | |
---|
5 | |
---|
6 | // The setTimeout calls in setting focus are only necessary in IE. |
---|
7 | // Without them the resetting of focus is erratic, and depends on who |
---|
8 | // previously had the focus. |
---|
9 | |
---|
10 | function putbutton() { |
---|
11 | $('#resp').html('<button id="clickme">click me</button>'); |
---|
12 | setTimeout( function() {$('#clickme').focus()},0) |
---|
13 | // not enclosing $('#clickme').focus() in setTimeout doesn't work all the time |
---|
14 | } |
---|
15 | |
---|
16 | function putinput() { |
---|
17 | $('#resp').html('<input type="text" width=20 id="typeme" name="typeme"/>'); |
---|
18 | setTimeout( function() {$('#typeme').focus()},0) |
---|
19 | // not enclosing $('#typeme').focus() in setTimeout doesn't work at all |
---|
20 | } |
---|
21 | |
---|
22 | |
---|
23 | |
---|
24 | $(document).ready( function() { |
---|
25 | |
---|
26 | $('#change2button').click( putbutton ); |
---|
27 | $('#change2input').click( putinput ); |
---|
28 | |
---|
29 | } |
---|
30 | ); |
---|
31 | |
---|
32 | </script> |
---|
33 | <body> |
---|
34 | <button id="change2button">change to a button</button> |
---|
35 | <button id="change2input">change to an input</button><br /> |
---|
36 | <span id="resp">Click one of the buttons to change me to a control</span> |
---|
37 | </body> |
---|