JavaScript:SetEvent

出自 ProgWiki
前往: 導覽搜尋

用途

程式碼

function SetEvent(elem, type, handle)
{
	if (elem)
	{
		if (elem.addEventListener)	//FireFox
			elem.addEventListener(type, handle, false);
		else if (elem.attachEvent)	//IE
			elem.attachEvent("on" + type, handle);
	}
}
 
function RemoveEvent(elem, type, handle)
{
	if (elem)
	{
		if (elem.removeEventListener)	//FireFox
			elem.removeEventListener(type, handle, false);
		else if (elem.detachEvent) 	//IE
			elem.detachEvent('on' + type, handle);
	}
}

相關

  • ASP.NET AJAX 的
    • Sys.UI.DomEvent.addHandler(element, eventName, handler)
    • Sys.UI.DomEvent.removeHandler(element, eventName, handler)