<html>
<head>
<script type="text/javascript">
<!--
var toLink = "aa.html";
function addLink(){
var areaValues = document.getElementById("textarea2").value;
var textArea = document.getElementById("textarea2");
var currSelect = "";
if(document.selection){
var sel = document.selection.createRange();
if(sel.text.length > 0){
currSelect = sel.text;
}
}else if(textArea.selectionStart || textArea.selectionStart == "0"){
var startP = textArea.selectionStart;
var endP = textArea.selectionEnd;
if(startP != endP){
currSelect = textArea.value.substring(startP,endP);
}
}
var result = "<a href='" + toLink + "' >" + currSelect + "</a>";
var start = areaValues.substring(0,areaValues.indexOf(currSelect));
var end = areaValues.substring(areaValues.indexOf(currSelect) +currSelect.length,areaValues.length);
textArea.value = start + result + end;
}
function setLink(link){ toLink = link; }
//-->
</script>
</head>
<body>
<table>
<tr>
<td> <input type="button" id="recverID" value="加上超链接" οnclick="addLink()"/> </td>
</tr>
<tr>
<td valign="top" height="31%">
<!--目标: <input type="text" id="recverID" /-->
<table cellpadding="0" cellspacing="0" border="0" width="100%" >
<tr>
<td width="3%" style="font-size:14px; font-weight:bold;">
<p>内 </p> <p> </p> <p>容 </p>
</td>
<td width="84%">
<textarea name="textarea2" class="textarea" rows="7" >
</textarea>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
为选择的文本内容加超链接--对当前选中文本的应用
最新推荐文章于 2022-09-27 21:09:25 发布