通常我会通过类似以下方式为某些事件注册javascript函数:
myBtn.Attributes.Add("onClick", "Validate(getElementById( "+txtFirstName.ClientID + " ));");
我一直在单独使用getElementById
,或者换句话说,没有在前面添加document。但是最近当我尝试使用getElementById
而不是document.getElementById
时,我的页面会出现错误。为什么会这样?奇怪的是,我有一个网站,其中一个页面允许我只使用getElementById
,但另一个页面如果我只使用getElementById
,则会引发javascript错误,并且只有使用document.getElementById
才能正常工作。
Anyone know why this is? Should I be using document.getElementById
everywhere, regardless of whether it works without the document prefix?
EDIT: Could it have anything to do with the fact that one page is using AJAX and the other isn t?