document.getElementById() VS. getElementById()

前端 未结 6 1434
情书的邮戳
情书的邮戳 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条回答
  •  暖寄归人
    2020-12-07 04:14

    You should use the full document.getElementById(). If you find that too verbose, you could use jQuery:

    $('#' + id)
    

    or you could create an alias at the top of your script:

    var byID = document.getElementById;
    

提交回复
热议问题