How to access object properties containing special characters?

前端 未结 1 1942
走了就别回头了
走了就别回头了 2020-11-21 05:03

I have a form DOM element:

var virDom = document.getElementsByTagName(\"form\")[0];

virDom has two fields with ID

1条回答
  •  失恋的感觉
    2020-11-21 05:23

    Use bracket notation:

    virDom['creditId']
    virDom['pwdId..']
    

    This applies to any object, and it is particularly useful for non-identifier-safe characters and also for accessing keys that you may not know ahead of time.

    0 讨论(0)
提交回复
热议问题