点击下面的运行,可预览代码效果<br>
代码如下:<br>
<script>
//获取一个对象
function getByid(id) {
if (document.getElementById) {
return document.getElementById(id);
} else if (document.all) {
return document.all[id];
} else if (document.layers) {
return document.layers[id];
} else {
return null;
}
}
//运行框操作
function creatID(DivID){
var objs=getByid(DivID).getElementsByTagName('textarea');
var inps=getByid(DivID).getElementsByTagName('input');
var buts=getByid(DivID).getElementsByTagName('button');
var labs=getByid(DivID).getElementsByTagName('label');
for (i=0; i<objs.length; i++) {
objs[i].id="runcode"+i;
inps[i].id=i
buts[i].id=i
labs[i].id=i
}
}
function runCode(obj){ //定义一个运行代码的函数,
var code=getByid("runcode"+obj).value;//即要运行的代码。
var newwin=window.open('','',''); //打开一个窗口并赋给变量newwin。
newwin.opener = null // 防止代码对论谈页面修改
newwin.document.write(code); //向这个打开的窗口中写入代码code,这样就实现了运行代码功能。
newwin.document.close();
}
//复制代码
function doCopy(obj) {
if (document.all){
textRange = getByid("runcode"+obj).createTextRange();
textRange.execCommand("Copy");
alert("代码已经复制到剪切板");
}else{
alert("此功能只能在IE上有效\n\n请在文本域中用Ctrl+A选择再复制")
}
}
//另存代码
function saveCode(obj) {
var winname = window.open('','','width=0,height=0,top=200,left=200px');
winname.document.open('text/html', 'replace');
winname.document.write(obj.value);
winname.document.execCommand('saveas','','CSS动态滑动菜单.html');
winname.close();
}
</script>
<textarea id="runcode0" cols="72" rows="9"> <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>中国设计秀cnwebshow.com---跟随鼠标的图片</title>
<script LANGUAGE="JavaScript">
var newtop=0
var newleft=0
if (navigator.appName == "Netscape") {
layerStyleRef="layer.";
layerRef="document.layers";
styleSwitch="";
}
else
{
layerStyleRef="layer.style.";
layerRef="document.all";
styleSwitch=".style";
}
function doMouseMove() {
layerName = 'iit'
eval('var curElement='+layerRef+'["'+layerName+'"]')
eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"')
eval('curElement'+styleSwitch+'.visibility="visible"')
eval('newleft=document.body.clientWidth-curElement'+styleSwitch+'.pixelWidth')
eval('newtop=document.body.clientHeight-curElement'+styleSwitch+'.pixelHeight')
eval('height=curElement'+styleSwitch+'.height')
eval('width=curElement'+styleSwitch+'.width')
width=parseInt(width)
height=parseInt(height)
if (event.clientX > (document.body.clientWidth - 5 - width))
{
newleft=document.body.clientWidth + document.body.scrollLeft - 5 - width
}
else
{
newleft=document.body.scrollLeft + event.clientX
}
eval('curElement'+styleSwitch+'.pixelLeft=newleft')
if (event.clientY > (document.body.clientHeight - 5 - height))
{
newtop=document.body.clientHeight + document.body.scrollTop - 5 - height
}
else
{
newtop=document.body.scrollTop + event.clientY
}
eval('curElement'+styleSwitch+'.pixelTop=newtop')
}
document.onmousemove = doMouseMove;
</script>
</head>
<body>
<!-- 以下代码是设定此页的鼠标样式代码 -->
<script language="javascript">
if (navigator.appName == "Netscape") {
}
else
{
document.write('<div ID=OuterDiv>')
document.write('<img ID=iit src="images/flag.gif" STYLE="position:absolute;TOP:5pt;LEFT:5pt;Z-INDEX:10;visibility:hidden;">')
document.write('</div>')
}
</script>
</body>
</html>
</textarea>
<br>
<input type="button" value="运行代码" id="0" onClick="runCode(this.id)">
<input type="button" value="复制代码" id="0" onClick="doCopy(this.id)">
<input type="button" value="保存代码" id="0" onClick="saveCode(runcode0)"> <br>[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

