网页中常用的剪切、全选等代码
来源:互联网 发布:淘宝后台客服电话 编辑:程序博客网 时间:2024/06/03 17:25
js部分:
<script type="text/javascript">
function RunCode()//运行代码
{
var code=event.srcElement.parentElement.children[0];
var newwin=window.open('','','');
newwin.opener = null;
newwin.document.write(code.value);
newwin.document.close();
}
function SelectCode() //全选代码
{
var code=event.srcElement.parentElement.children[0]
code.focus();
code.select();
}
function CopyCode() //复制代码
{
var code=event.srcElement.parentElement.children[0]
code.focus();
code.select();
document.execCommand('copy');
}
function CutCode() //剪切代码
{
var code=event.srcElement.parentElement.children[0]
code.focus();
code.select();
document.execCommand('cut');
}
function PasteCode() //粘贴代码
{
var code=event.srcElement.parentElement.children[0]
code.focus();
document.execCommand("paste");
}
function ClearCode() //清除代码
{
var code=event.srcElement.parentElement.children[0]
code.value='';
}
function SaveCode() //保存代码
{
var code=event.srcElement.parentElement.children[0]
var winname = window.open('', 'savewindow', 'top=10000');
winname.document.open('text/html', 'replace');
winname.document.writeln(code.value);
winname.document.execCommand('saveas','','code.htm');
winname.close();
}
function Goto(ln) //跳转代码
{
if(!/^\d+$/.test(ln) || ln==0) return;
var obj=event.srcElement.parentElement.children[0];
var rng=obj.createTextRange();
var arr=obj.value.split(/\n/);
if(ln>arr.length) ln =arr.length;
var str_tmp = "";
for(var i=0; i<ln-1; i++){
str_tmp +=arr[i];
}
rng.moveStart('character',str_tmp.length);
str_tmp="";
for(i=ln; i<arr.length; i++){
str_tmp +=arr[i];
}
rng.moveEnd('character',-str_tmp.length);
rng.select();
return;
}
function showdir()
{
top.fstMain.cols="228,*";
showtoc.style.display="none";
}
function hidedir()
{
top.fstMain.cols="-5,*";
top.fraRightbar.showtoc.style.display="";
}
</script>
html部分:
<textarea name="codes" id="codes" rows="15" cols="100"></textarea><br/><input type="button" value="运行代码" onclick="RunCode()"> <input type="button" value="复制代码" onclick="CopyCode()"> <input type="button" value="另存代码" onclick="SaveCode()"> <input type="button" value="跳 转" onclick="Goto(prompt('请输入要跳转到第几行?','1'))" accesskey="g"> 提示:您可以先修改部分代码再运行</div>
- 网页中常用的剪切、全选等代码
- 网页中常用的两个全选js
- 网页中常用的技巧、代码、样式等
- 监听EditText的复制、粘贴、全选、剪切、选择等状态
- UITextView中打开或禁用复制,剪切,选择,全选等功能
- 网页中常用的JavaScript代码
- 网页中常用的Javascript代码
- html网页表单中禁用复制、右键、粘贴、剪切等方法
- 禁止网页右键、全选CTRL+A、复制的代码
- 常用网页中嵌套播放器的代码实例
- 网页设计中常用的37个javascript代码
- 常用的网页设计代码
- 常用到的网页代码
- vi全选及剪切
- 网页常用HTML,ASP,JavaScrip等代码(一)
- 常用网页HTML,ASP,JavaScrip等代码(二)
- 剪切汉字字符串的代码!
- 自定义EditText 的复制 、粘贴、剪切等
- 实现一个ntohll
- spoj Circleland题解
- 互锁函数
- What is different between ClassLoader.getResourceAsStream() and Class.getResourceAsStream()?
- Oracle Database 11gR2:面向 DBA 和开发人员的重要特性
- 网页中常用的剪切、全选等代码
- 【jiasuba】更改文件打开方式最简单的两种方法
- JavaScript实现 页面滚动图片加载
- 如何利用抽象工厂更换数据库
- redo log的管理
- source insight 宏
- Cocos2D: Additive Coloring & Flash Style Tinting
- 运行库
- IIC和SPI总线协议