Javascript实用函数
function addLoadEvent(fun) {
var oldonload = window.onload;
if(typeof(window.onload) != 'function') {
window.onload = fun;
} else {
window.onload = function() {
oldonload();
fun();
}
}
}
//function insertAfter(newElement, targentElement)
function insertAfter(insertedNode, adjacentNode) {
var parent = adjacentNode.parentNode;
if(parent.lastChild == adjacentNode) {
parent.appendChild(insertedNode);
} else {
parent.insertBefore(insertedNode, adjacentNode.nextSibling);
}
}
相关文档:
Evaluates an expression after a specified number of milliseconds has elapsed.
(在指定时间过后执行指定的表达式)
Syntax:
iTimerID = window.setTimeout(vCode, iMilliSeconds [, sLanguage])
Parameters
vCode
Required. Variant that specifies the function pointer or string that indicates the code to be ......
网页可见区域宽:document.body.clientWidth;
网页可见区域高:document.body.clientHeight;
网页可见区域高:document.body.offsetWidth (包括边线的宽);
网页可见区域高:document.body.offsetHeight (包括边线的宽);
网页正文全文宽:document.body.scrollWidth;
网页正文全文高:document.body.scrollHeight;
......
<script>
var i = 0;
function insertTr(obj)
{
var tr1 = tb.insertRow(obj.rowIndex+1);
......
1. 应用 Array.prototype.join实现字符合并
方法1.
String.prototype.times = function(n) {
return Array.prototype.join.call({length:n+1}, this);
};
"js".times(5) // => "jsjsjsjsjs"
方法2.
var ArrayTest=new Array("HE","LL","O");
var hello = Array.prot ......