Ik ben bezig met een simpele editor a la GoT. Hieronder staat hoever ik nu ben. In regel 36 staat txtarea.focus(). Ik dacht dat ik hiermee de focus weer op de textarea zou krijgen, zodat de gebruiker meteen door kan tikken. Dat is alleen niet zo. Wie ziet het probleem? Ik heb ook al de txtarea.focus() in de onlick van de buttons gezet, maar ook dat levert geen resultaat op.
HTML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
| <script language="JavaScript" type="text/javascript"> function initEditor() { txtarea = document.getElementById('editor'); } // Nu nog copy-paste GoT - pas nog aan uiteraard :) function mozWrap(type) { var sStart = txtarea.selectionStart; var sEnd = txtarea.selectionEnd; text = txtarea.value.substring(sStart, sEnd); text = txt_replace(type, text); txtarea.value = txtarea.value.substr(0, sStart) + text + txtarea.value.substr(sEnd); var nEnd = sStart + text.length; txtarea.setSelectionRange(nStart, nEnd); } function IEWrap(type) { text = document.selection.createRange().text; text = txt_replace(type,text) document.selection.createRange().text = text; } function wrapSelection(type) { if (document.all) { IEWrap(type); } else if (document.getElementById) { mozWrap(type); } txtarea.focus(); } function txt_replace(type, text) { switch (type) { case 'p': text = '<p>'+text+'</p>'; break; case 'bold': text = '<b>'+text+'</b>'; break; case 'italic': text = '<i>'+text+'</i>'; break; case 'h1': text = '<h1>'+text+'</h1>'; break; case 'h2': text = '<h2>'+text+'</h2>'; break; case 'h3': text = '<h3>'+text+'</h3>'; break; } return text; } </script> <input type="button" value=" B " onclick="wrapSelection('bold');"> <input type="button" value=" I " onclick="wrapSelection('italic');"> <select onchange="wrapSelection(this.options[this.options.selectedIndex].value); this.selectedIndex=0"> <option selected>Heading</option> <option value='p'>Paragraph</option> <option value='h1'>H1</option> <option value='h2'>H2</option> <option value='h3'>H3</option> </select> <br> <textarea id="editor" name="data[content]" rows="10" cols="50"></textarea> <script type=text/javascript>initEditor();</script> |
[ Voor 63% gewijzigd door Reveller op 25-04-2005 21:36 ]
"Real software engineers work from 9 to 5, because that is the way the job is described in the formal spec. Working late would feel like using an undocumented external procedure."
