...

View Full Version : JS replace function



csam0003
04-16-2009, 07:06 PM
Hi all,
I am trying to implement a function whereby the user selects some text and on click of a button a set of span tags are wrapped around that selected text. If the text contains within it another set of tags(for example a href) it will surround the text with span tags aswell.


<p> I went to the market yesterday to buy some <a href="url">fruit and vegetables</a> and then walked home instead catching the car </p> <p> The next day I did the same thing </p>

So if the user selects from "I went to the" to "The next day" it would look something like this:

<p><span color = 'blue'> I went to the market yesterday to buy some </span> <a href="url"><span color = 'blue'>fruit and vegetables</span></a><span color = 'blue'> and then walked home instead catching the car<span> </p> <p><span color = 'blue'> The next day </span color=blue> I did the same thing </p>


Any idea how I can do this?

Thanks

Kind regards

Chris

renzaijiang
04-17-2009, 02:46 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>document.selection 的 createRange</title>
</head>
<body>

<div>please select me<div>
<div><input type="button" value="makeBold" onclick="javascript:Bold();" /></div>
<script type="text/javascript" language="javascript">
<!--
function Bold()
{
var r = document.selection.createRange();
//use this object to get select area;
r.execCommand("Bold");
}
-->
</script>

</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum