[英]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. 您可以选择在每个控件触发onchange事件时运行一些自定义JavaScript。 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.
有一个“事件”选项卡,您可以在其中指定在为控件触发onchange事件时运行的JavaScript函数。 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:
这意味着您可以拥有一个通用的JavaScript函数,如下所示:
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. 因此,您可以设置控件以调用函数“ control_onchange”,并将执行上下文(包含有关控件的有用信息)作为参数传递。
See MSDN for the list of available actions with this context. 有关此上下文的可用操作的列表,请参见MSDN 。
Some examples: 一些例子:
To get the field name: 要获取字段名称:
context.getEventSource().getName();
To get the field value: 要获取字段值:
context.getEventSource().getValue();
您的onchangeevent事件的第一个变量将是具有所有相关信息的事件,包括触发事件的元素
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.