在用户控件更换body.onload [英] Replacing body.onload in a user control

查看:75
本文介绍了在用户控件更换body.onload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我重构,使用℃的页面;身体的onload =myJS();> 到用户控件。我明白我可以使用负载的服务器端脚本登记做到这一点。

I am refactoring a page that uses <body onload="myJS();"> to a user control. I understand I can do it using server side script registration on load.

如果我想这样做在客户端(ASCX),我会怎么做呢?

If I want to do it on the client side (ascx), how would I do this?

推荐答案

从的 http://snipplr.com/view/3116/cross-browser-add-event-listener/

// Cross-browser implementation of element.addEventListener()

function addEvent(evnt, elem, func) {
    if (elem.addEventListener) // W3C DOM
        elem.addEventListener(evnt,func,false);
    else if (elem.attachEvent) { // IE DOM
        var r = elem.attachEvent("on"+evnt, func);

    return r;
}

使用这样的:的addEvent(窗口,your_onload_handler)。或者你可以只使用这个jQuery和很多其他的东西。

Use it like this: addEvent(window, your_onload_handler). Or you could just use jquery for this and a lot of other things.

这篇关于在用户控件更换body.onload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆