xbl12
Programmer
- Dec 12, 2006
- 66
Hi;
i'd like to change some letters from a paragraph when i load in a page.
I can do in the following two ways, it works fine. but i do want the following way.
<body onLoad="s2t()">
and i write my code as following, but it does not work, could anyone help, please.
i'd like to change some letters from a paragraph when i load in a page.
I can do in the following two ways, it works fine. but i do want the following way.
<body onLoad="s2t()">
and i write my code as following, but it does not work, could anyone help, please.
Code:
<html>
<head>
</head>
<body>
<script type="text/JavaScript">
s2t();
</script>
<div id="mydiv">
Vince Cervi, 41, who once held the Australian heavyweight title belt,
died from a wound to the abdomen at Preston, after the alleged confrontation reports the Herald Sun.
</div>
<script type="text/JavaScript">
function s2t(){
alert("welcome to y");
var oldchars = new Array("A","B","C","D","E","a","b","c","d","e"); // original letters
var newchars = new Array("N","Y","G","L","W","n","y","g","l","w"); // letters to change to
var mytext = document.getElementById("mydiv").innerHTML;
var oldlen = oldchars.length;
for (var i = 0; i < oldlen; i++) {
var changefrom = oldchars[i];
var change2 = newchars[i];
var replaceVal = new String(changefrom);
var match = new RegExp(replaceVal, 'g');
mytext = mytext.replace(match, change2);
}
document.getElementById("mydiv").innerHTML = mytext;
}
</script>
</body>
</html>