JS Support OCX Control Events (event), when the OCX control defined event occurs, JS can catch the event and the event to handle the corresponding.
Personal understanding, is actually the response of the event by WHO to complete, OCX control itself is certainly achievable, JS provides this mechanism so that JS can also complete OCX control event response.
Simple examples are as follows:
First add a custom event in the OCX control (predefined events are similar, such as mouse clicks, did not personally try, the sensory principle should be the same),
The event should belong to the window, so right-click on the Ctrl class, Add->add event, as shown in the following figure:
In the Open dialog box, enter the event name, such as onchange, if you need parameters, set parameter information, click [Finish], the wizard automatically generates code, as follows
The
code is as follows:
//Event mapping
Begin_event_map (Ch_ocxctrl, COleControl)
event_custom_id ("OnChange", Eventidchange, OnChange, Vts_none)
End_event_map ()
OK, the event definition is complete, and then you need to trigger the event to invoke OnChange () in a function of the OCX control to trigger the event.
The event definition for the OCX control is thus completed.
Next is the JS in the response to the event, the code is as follows,
The
code is as follows:
<script language= "javascript" for= "Myctrl" event= "OnChange ()" type= "Text/javascript" >
call (); Can also write the operation code directly
</script>
Myctrl is the OCX control object ID of the control on this page (name seems to be OK, not tried) and can manipulate the object in JavaScript.
OnChange () is an event in an OCX control, where the event name must be the same as the event name in the OCX control.
If the event takes a parameter, the OCX control passes the corresponding argument when the event is triggered, for example, the event has two parameters P1 and P2, which can be written as event = "OnChange (param1,param2)", at which point param1, param2 will correspond to receive P1, p2, Same call (PARAM1,PARAM2).
The
code is as follows:
<script type= "Text/javascript" language=javascript>
function Call (PARAM1,PARAM2)
{
alert (PARAM1+PARAM2); Operation Code
}
</script>
Write hastily, language expression is not very clear, the basic idea is this, used for the memo.