JavaScript DOM编程艺术中的代码片段
第一个对《JavaScript DOM编程艺术》中的代码做了点修改,用途是判断当前栏目。初学javascript,算交作业了!书中还有个是表格隔行换色的。我以为这个可以用ccs来实现,而且这种表现层的东西就应该是css的事情。
<script type="text/javascript">
c_link = function(){
this.t_attribute = new Array();
this.judge = function(){
var t_element = document.getElementById(this.t_attribute[0]).getElementsByTagName("a");
for (var i=0;i<=t_element.length;i++){
var t_link = t_element[i].getAttribute("href");
var c_href = window.location.href;
if (c_href.indexOf(t_link) != -1){
o_class = this.t_attribute[1];
t_class = this.t_attribute[2];
t_element[i].onmouseover = function (){this.className = o_class;}
t_element[i].onmouseout = function (){this.className = t_class;}
t_element[i].className += t_class;
}
}
}
}
var aa = new c_link();
aa.t_attribute = ["nav","over_class","c_class"];
aa.judge();
aa = null;
function addloadEvent(func){
var oldonload = window.onload;
if (typeof oldonload !='function'){
window.onload=func;
}else{
window.onload=function(){;
oldonload();
func();
}
}
}
addloadEvent(func);
</script>
c_link = function(){
this.t_attribute = new Array();
this.judge = function(){
var t_element = document.getElementById(this.t_attribute[0]).getElementsByTagName("a");
for (var i=0;i<=t_element.length;i++){
var t_link = t_element[i].getAttribute("href");
var c_href = window.location.href;
if (c_href.indexOf(t_link) != -1){
o_class = this.t_attribute[1];
t_class = this.t_attribute[2];
t_element[i].onmouseover = function (){this.className = o_class;}
t_element[i].onmouseout = function (){this.className = t_class;}
t_element[i].className += t_class;
}
}
}
}
var aa = new c_link();
aa.t_attribute = ["nav","over_class","c_class"];
aa.judge();
aa = null;
function addloadEvent(func){
var oldonload = window.onload;
if (typeof oldonload !='function'){
window.onload=func;
}else{
window.onload=function(){;
oldonload();
func();
}
}
}
addloadEvent(func);
</script>
-
« 单行图文混排垂直居中
|
生日快乐»
- 2008-3-27 4:53
- 艺术pk技术