Call a JavaScript function name using a string?

前端 未结 10 1127
孤独总比滥情好
孤独总比滥情好 2020-11-30 07:07

How can I hook up an event to a function name I have defined as a string?

I\'m using Prototype.js, although this is not Prototype-speficic.

$(inputId         


        
10条回答
  •  佛祖请我去吃肉
    2020-11-30 07:59

    Looks like formData.fields[x].onclick holds the name of a global function? If so try:

    $(inputId).observe('click', window[formData.fields[x].onclick]);
    

提交回复
热议问题