Dynamic variable names in Javascript

后端 未结 1 2026
北海茫月
北海茫月 2021-01-16 09:34

I use jQuery Impromptu prompts in my application and they\'re very helpful.

However to call the Impromptu prompts you need to specify the button names and their retu

相关标签:
1条回答
  • 2021-01-16 10:03

    Since property names in an object literal can be identifiers (rather than strings), you can't use a variable for them.

    You have to create the object, and then use square bracket notation to assign the values.

    function showprompt(question, button1, button2) {
      var buttons = { };
      buttons[button1] = true;
      buttons[button2] = false;
      $.prompt(question,{ buttons: buttons });
    }
    
    0 讨论(0)
提交回复
热议问题