Example of the event response of the OCX control implemented by JS

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.