Java Reference
In-Depth Information
<head>
<title>example 6</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8” />
<script type=”text/JavaScript”>
function button1_onclick()
{
var myString = “<table align=center><tr><td>”;
myString = myString + “Hello World</td></tr></table>”;
myString = myString +”<br><h2>Heading</h2>”;
var myRegExp = /<[^>\r\n]+>|[^<>\r\n]+/g;
var resultsArray = myString.match(myRegExp);
document.form1.textarea1.value = “”;
document.form1.textarea1.value = resultsArray.join (“\r\n”);
}
</script>
</head>
<body>
<form name=”form1”>
<textarea rows=”20” cols=”40” name=”textarea1”></textarea>
<input type=”button” value=”Split HTML” name=”button1”
onclick=”return button1_onclick();”>
</form>
</body>
</html>
Save this fi le as ch9_examp6.htm . When you load the page into your browser and click the Split HTML
button, a string of HTML is split, and each tag is placed on a separate line in the text area, as shown in
Figure 9-15.
Figure 9-15
The function button1_onclick() defi ned at the top of the page fi res when the Split HTML button is
clicked. At the top, the following lines defi ne the string of HTML that you want to split:
function button1_onclick()
{
var myString = “<table align=center><tr><td>”;
Search WWH ::




Custom Search