dungping5
10-01-2005, 02:30 AM
I am designing a simple word processor for Chinese by using the IE-only feature of contentEditable. Chinese has four tones. I use superscripts 1 through 4 for these tones. When typing the numbers 1 to 4, they have been made to appear as superscripts. Following is the url. If interested, you can open it, and test editing in the colored area.
http://www.pinyinology.com/pinyin/content.html
But the code needs improvement. I've explained my expectations in the page. I am very new for programming, and am looking for help at this forum. Following is part of the code:
<html>
<head>
<script type='text/javascript'>
function sup() {
var what = document.getElementById('edit').innerHTML;
what = what.replace(/\<sup>/gi,"");
what = what.replace(/\<\/sup>/gi,"");
var temp;
for (var i=0; i < what.length; i++) {
var a = what.charAt(i);
if ((a >= 1) && (a <= 4)) {
temp = what.substr(0,i);
temp += '<sup>' + a + '</sup>';
temp += what.substr(i+1);
i = i + '<sup>#</sup>'.length;
what = temp;
}
}
document.getElementById('edit').innerHTML = what;
}
</script>
</head>
<body>
<div contentEditable='true' onkeyup='sup()' id='edit'>
</div>
</body>
</html>
Thanks in advance.
Dung Ping
http://www.pinyinology.com/pinyin/content.html
But the code needs improvement. I've explained my expectations in the page. I am very new for programming, and am looking for help at this forum. Following is part of the code:
<html>
<head>
<script type='text/javascript'>
function sup() {
var what = document.getElementById('edit').innerHTML;
what = what.replace(/\<sup>/gi,"");
what = what.replace(/\<\/sup>/gi,"");
var temp;
for (var i=0; i < what.length; i++) {
var a = what.charAt(i);
if ((a >= 1) && (a <= 4)) {
temp = what.substr(0,i);
temp += '<sup>' + a + '</sup>';
temp += what.substr(i+1);
i = i + '<sup>#</sup>'.length;
what = temp;
}
}
document.getElementById('edit').innerHTML = what;
}
</script>
</head>
<body>
<div contentEditable='true' onkeyup='sup()' id='edit'>
</div>
</body>
</html>
Thanks in advance.
Dung Ping