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);
}
}
相关文档:
//获取当前文件全路径
<script language="javascript">
alert(window.location.href);
alert(window.location);
alert(location.href);
alert(parent.location.href);
alert(top.location.href);
alert(document.location.href);
alert(document.URL);
</scri ......
引言
JavaScript不是按面向对象的思想设计的程序语言,所以它不具备像现有的面向对象的语言那样的功能,但是面向对象的思想是如此的深入人心,以至于JavaScript也削尖了脑袋“面向对象”。果真,通过一些特殊的处理,JavaScript也具有了基本的面向对象的功能。
......
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 ......
删除行
<script>
function del(obj)
{
obj.parentNode.parentNode.removeNode(true);
}
</script>
<body& ......