今天做MOSS的前台的时候,需要用到一个onload事件,在页面启动的时候就加载JS函数,如下代码
<script language="javascript" type="text/javascript">
window.onload = function () {
var scrollup = new ScrollText("listcontent");
scrollup.LineHeight = 60;
scrollup.Amount = 2;
scrollup.Start();
}
</script>
结果,运行后,发现它将母版页面body里面的onload事件给冲突掉了,最后找到一个解决方法,将代码写成如下:
<script language="javascript" type="text/javascript">
function srcollnews() {
var scrollup = new ScrollText("listcontent");
scrollup.LineHeight = 60;
scrollup.Amount = 2;
scrollup.Start();
}
if (document.all) {
window.attachEvent('onload', srcollnews)
}
else {
window.addEventListener('load', srcollnews, false);
}
</script>