<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
要完成此效果需要两个步骤
第一步:把如下代码加入到<head>区域中
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var text = "";
function getActiveText(e) {
text = (document.all) ? document.selection.createRange().text : document.getSelection();
document.theform.text.value = text;
return true;
}
document.onmouseup = getActiveText;
if (!document.all) document.captureEvents(Event.MOUSEUP);
// End -->
</script>
第二步:把如下代码加入到<body>区域中
<center>
<form name=theform>
被选中的文本: <input type=text name=text value="">
</form>
</center>
本文介绍了一种使用JavaScript实现的简单方法,可以在用户选中页面上的文本时自动捕获所选内容并显示出来。该方法分为两步:首先在<head>部分引入必要的JavaScript代码,其次在<body>中设置用于展示选中文字的输入框。

2131

被折叠的 条评论
为什么被折叠?



