document.getElementById() VS. getElementById()

前端 未结 6 1441
情书的邮戳
情书的邮戳 2020-12-07 03:43

It is common for me to register javascript functions for certain events by doing something like:

myBtn.Attributes.Add(\"onClick\", \"Validate(getElementById(         


        
6条回答
  •  猫巷女王i
    2020-12-07 04:10

    You should only use document.getElementById (even if I'd recommend using libraries like prototype or jquery to be able to use the $ sign).

    If you are able to use getElementById on its own, it's just because the browser you're using is doing some kind of trick to get it to work, but the correct way is to use the document variable.

提交回复
热议问题