javascript小技巧(转)
事件源对象
event.srcElement.tagName
event.srcElement.type
捕获释放
event.srcElement.setCapture();
event.srcElement.releaseCapture();
事件按键
event.keyCode
event.shiftKey
event.altKey
event.ctrlKey
事件返回值
event.returnValue
鼠标位置
event.x
event.y
窗体活动元素
document.activeElement
绑定事件
document.captureEvents(Event.KEYDOWN);
访问窗体元素
document.all("txt").focus();
document.all("txt").select();
窗体命令
document.execCommand
窗体COOKIE
document.cookie
菜单事件
document.oncontextmenu
创建元素
document.createElement("SPAN");
根据鼠标获得元素:
document.elementfromPoint(event.x,event.y).tagName=="TD
document.elementfromPoint(event.x,event.y).appendChild(ms)
窗体图片
document.images[索引]
窗体事件绑定
document.onmousedown=scrollwindow;
元素
document.窗体.elements[索引]
对象绑定事件
document.all.xxx.detachEvent('onclick',a);
插件数目
navigator.plugins
取变量类型
typeof($js_libpath) == "undefined"
下拉框
下拉框.options[索引]
下拉框.options.length
查找对象
document.getElementsByName("r1");
document.getElementById(id);
定时
timer=setInterval('scrollwindow()',delay);
clearInterval(timer);
UNCODE编码
escape() ,unescape
父对象
obj.parentElement(dhtml)
obj.parentNode(dom)
交换表的行
TableID.moveRow(2,1)
替换CSS
document.all.csss.href = "a.css";
并排显示
display:inline
隐藏焦点
hidefocus=true
根据宽度换行
style="word-break:break-all"
自动刷新
<meta HTTP-EQUIV="refresh" CONTENT="8;URL=http://c98.yeah.net">
简单邮件
<a href="mailto:aaa@bbb.com?subject=ccc&body=xxxyyy">
快速转到位置
obj.scrollIntoView(true)
锚
<a name="first">
<a href="#first">anchors</a> _fcksavedurl=""#first">anchors</a>"
网页传递参数
location.search();
可编辑
obj.contenteditable=true
执行菜单命令
obj.execCommand
双字节字符
/[^\x00-\xff]/
汉字
/[\u4e00
相关文档:
在地址栏输入:
javascript:str='';for%20(var1=0;var1<document.images.length;var1++){str+='\n'+document.images[var1].src};if(str!=''){document.write(str);void(document.close())}else{alert('No%20images!')}
然后查看新出来的页面的源代码
若要显示出来,则:
javascript:funcname='';for%20(var1=0;var ......
本文来自http://q.yesky.com/group/review-17634017.html,另外还添加一些里面技术的链接。
离线事件(Online and offline events):
https://developer.mozilla.org/En/Online_and_offline_events
https://bug336359.bugzilla.mozilla.org/attachment.cgi?id=220609
http://ejohn.org/blog/offline-events/
postMessage ......
在开发过程中经常遇到要调整小数的格式,如保留小数点后两位等等。方法也颇为常见,备忘如下。
第一种,利用math.round
var original=28.453
1) //round "original" to two decimals
var result=Math.round(original*100)/100; //returns 28.45
2) // round "original" to 1 dec ......
引用是一个指向对象实际位置的指针。
例1:
var obj = new Object();
var objRef = obj; //obj与objRef指向同一个对象,objRef是一个引用
自修改(self-modifying)
例2:
var items = new Array("one","two","three");
var itemsRef = items; //创建一个引用
items.push("four");
alert(items.length == items ......
1 Add the following code to .aspx
<script>
function fresh() {
{
window.opener.document.getElementById("ControlId").click(); //ControlId -- ......