简体   繁体   English

如何获得调用javascript函数的控件?

[英]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.

相关问题 如何在 JavaScript 中组合函数调用? - How can I combine function calls in JavaScript? 我有一个调用PHP函数的JavaScript函数。 如何将结果显示在html中而不显示在警报框中? - I have a JavaScript function that calls a PHP Function. How can I get the results to display in the html and not in an alert box? 如何在JavaScript中添加/附加所有函数调用的结果 - How can I prepend/append the results of all function calls in JavaScript 如何在JavaScript中通过多个异步调用向函数添加回调? - How can I add a callback to a function with multiple async calls in JavaScript? 如何确保javascript函数可以在多个调用中使用? - How can I ensure that a javascript function will work on multiple calls? 如何从后面的代码中获取ID传递给javascript函数的控件的值 - How can I get the value of a control whose ID was passed to javascript function from code behind 如何从Firebug Profiler中获取函数调用的参数? - How Can I Get the Arguments of Function Calls from the Firebug Profiler? 如何在运行时获取 Javascript Function 调用/跟踪 - How to get Javascript Function Calls/Trace at Runtime Javascript-如何确保(递归)函数调用上的控制流 - Javascript - how to ensure control flow on (recursive) function calls 如何在Webbrowser控件中调用javascript函数? - How can i invoke javascript function within the webbrowser control?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM