简体   繁体   中英

How can I get the control that calls javascript function?

有没有一种方法可以在javascript运行时返回称为onchange事件的控件?

You can choose for some custom JavaScript to run when the onchange event fires for each control. Open a form to customize it > select a control > click properties. There is an "Events" tab where you can specify JavaScript functions to run when the onchange event fires for the control. One of the options for this event is " Pass execution context as first parameter ". This means you could have a generic JavaScript function like so:

function control_onchange(context)
{
    // to get the control which caused the onchange event
    var control = context.getEventSource();
}

Therefore you could setup a control to call the function "control_onchange" and pass the execution context (which has useful information about the control) as the paramater.

See MSDN for the list of available actions with this context.

Some examples:

  • To get the field name:

     context.getEventSource().getName(); 
  • To get the field value:

     context.getEventSource().getValue(); 

您的onchangeevent事件的第一个变量将是具有所有相关信息的事件,包括触发事件的元素

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM