Accessing dynamic property names in Jquery/Javascript

前端 未结 3 1734
不知归路
不知归路 2020-12-22 03:23

In a plugin I\'m writing, the dev can specify options, which I\'m storing and referencing like so:

(function( $, window) {
    $.widget(\"mobile.plug\", $.mo         


        
3条回答
  •  不知归路
    2020-12-22 03:31

    What you're looking for is bracketed notation with strings:

    for (var i = 0; i

    ...assuming that el.jqmData("panel") returns "mid", "menu", etc.

    In JavaScript, you can refer to a property with either dotted notation and a literal (obj.foo), or bracketed notation and a string (obj["foo"]). In the latter case, it doesn't have to be a literal string, it can be the result of an expression.

提交回复
热议问题