java技术,博客,论坛 |
Javascript 小技巧全集(4) |
//移动的图层,拖动 1.<span style='position:absolute;width:200;height:200;background:red' onmousedown=MouseDown(this) onmousemove=MouseMove() onmouseup=MouseUp()>meizz</span>
<script language=javascript> var Obj; function MouseDown(obj) { Obj=obj; Obj.setCapture(); Obj.l=event.x-Obj.style.pixelLeft; Obj.t=event.y-Obj.style.pixelTop; } function MouseMove() { if(Obj!=null) { Obj.style.left = event.x-Obj.l; Obj.style.top = event.y-Obj.t; } } function MouseUp() { if(Obj!=null) { Obj.releaseCapture(); Obj=null; } } </script> 2. <div id="myDiv" src="logo.gif" ondrag="doDrag();" onmouseover="this.style.cursor='hand'" style="position:absolute;left=100;top=100;" onmousedown="doMouseDown();"> <a href="#" onclick="return false"><h1>wlecome</h1></a> </div> <script language="JavaScript" type="text/javascript"> var orgMouseX; var orgMouseY; var orgObjX; var orgObjY; function doDrag() { var myObject=document.all.myDiv; var x=event.clientX; var y=event.clientY; myObject.style.left=x-(orgMouseX-orgObjX); myObject.style.top=y-(orgMouseY-orgObjY); } function doMouseDown() { orgMouseX=event.clientX; orgMouseY=event.clientY; orgObjX=parseInt(document.all.myDiv.style.left); orgObjY=parseInt(document.all.myDiv.style.top); } </script> //文档状态改变 <iframe src="a.html" id="f" name="f" scrolling="no" frameborder=0 marginwidth=0 marginheight=0></iframe>
<script> var doc=window.frames["f"].document; function s(){ if (doc.readyState=="complete"){ document.all.f.style.height=doc.body.scrollHeight document.all.f.style.width=doc.body.scrollWidth } } doc.onreadystatechange=s </script> //刷新后不变的文本框
//访问剪贴板
//操作COOKIE function SetCookie(sName, sValue)
{ document.cookie = sName + "=" + escape(sValue) + "; "; } function GetCookie(sName) { var aCookie = document.cookie.split("; "); for (var i=0; i < aCookie.length; i++) { var aCrumb = aCookie[i].split("="); if (sName == aCrumb[0]) return unescape(aCrumb[1]); } } function DelCookie(sName) { document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;"; } //setTimeout增加参数 <script>
var _st = window.setTimeout; window.setTimeout = function(fRef, mDelay) { if(typeof fRef == 'function'){ var argu = Array.prototype.slice.call(arguments,2); var f = (function(){ fRef.apply(null, argu); }); return _st(f, mDelay); } return _st(fRef,mDelay); } function test(x){ alert(x); } window.setTimeout(test,1000,'fason'); </script> |
共7页: 上一页 [1] [2] [3] [4] [5] [6] [7]下一页 |
Copyright (C) 2004 http://www.onejava.com, Java技术联盟. All Rights Reserved