Cross-browser, javascript getAttribute() method?

前端 未结 3 1728
無奈伤痛
無奈伤痛 2020-12-14 03:45

trying to determine a decent, cross browser method for obtaining attributes with javascript? assume javascript library use (jQuery/Mootools/etc.) is not an option.

I

3条回答
  •  伪装坚强ぢ
    2020-12-14 04:35

    You are trying to access properties of ele before you've established if those properties exist. Try this kind of evidence chain:

    if (ele.attributes && ele.attributes[attr] && typeof ele.attributes[attr] == 'undefined')
    

    etc.

提交回复
热议问题