JQuery supports dynamic parameters to bind functions to events. jquery binds functions to events.
This example describes how jQuery can bind functions to events using dynamic parameters. Share it with you for your reference. The specific analysis is as follows:
The following js Code provides two methods to bind a function to an event. method 2 can pass dynamic
Routing event:Events are triggered and CLR events are handled by the host itself (this. raiseevent this. addhandler this. removehandler); The host consists of three parts: declaring and registering a route event (xxxevent), defining the CLR event wrapper (xxx {add, remove }) encapsulate the method (onfunction) that contains the code that triggers the routing event)Additional event:Events and CLR packaging (Registration and release) are all handled by
/* applies only to elements clicked in the content. For elements such as dragging, you need to work on the page yourself.* Mainly binds Touchstart and touchmove events, and determines how many pixels the finger moves after the user presses it.* If your finger moves less than 10 pixels, you still think the user is doing a click. If the moving distance exceeds 10 pixels, the execution of subsequent event listener functions is canceled. */Mobile Touchsta
ahref= "javascript:;"> + imgsrc= "/content/images/scene/vote004/jia.jpg"onclick= "Openimagesetdialog (this,1)"width= " the"> A a> the Li> + ul>HTMLProcessing of JSvar Mousebuttonflag = fa
JQuery binds events in four ways, and jquery binds events in four ways.
JQuery provides multiple ways to bind events. Each method has its own characteristics. It understands the similarities and differences between them and helps us make the right choices when writing code, this allows you to write elegant and easy-to-maintain code. Next, let's take a look at how
JQuery simulates click events to automatically trigger events
Sometimes, you need to simulate user operations to achieve the effect of clicking. For example, when a user enters the page, the click event is triggered without the user clicking it.
In JQuery, you can use the trigger () method to complete the simulation operation. For example, you can use the following code to trigger the click Event of a butto
1 usingSystem;2 usingSystem.Windows;//Implementing a weak event requires referencing the WindowsBase assembly3 4 namespaceexample explanation of events and weak events5 {6 class Program7 {8 Static voidMain (string[] args)9 {Ten vardealer =NewCardealer ();//This class contains an event handler, and a method for invoking it One A varMichael =NewConsumer ("Michael");//This class contains the name of a pers
Unbind ([Type],[data]) is the reverse operation of BIND (), removing the bound event from each matching element. If there are no parameters, all bound events are deleted. You can unbind a custom event that you have registered with bind (). If the event type is supplied as a parameter, only the binding event of that type is deleted. If you pass a handler function that is passed at bind time as the second argument, only that particular event handler wil
Take the Click event as an example:Normal bind event: $ ('. btn '). Click (function () {}) BindingOn binding event: $ (documnet). On (' Click ', ' btn2 ', function () {})So what is the difference between the two ways?Let's say the difference in one exampleThe ①click event is an element that gets all the classes named BTN1 after the page is loaded, and then binds the click event, and if you regenerate the BTN1 element by another operation, it does not have the Click event;② and on ()
MFC mouse events and mfc mouse events
1. Create a project named MFCBaseMessage
2. Select the basic dialog box mode and click Finish.3. Final
4. Right-click the Add Class Wizard
5. Add mouse events
6. Add the following code in ON_LButtonDown:
Void CMFCBaseMessageDlg: OnLButtonDown (UINT nFlags, CPoint point) {// TODO: add the message processing pr
JS: a simple method for dynamically adding events to objects. js Dynamic Object events
In WEB projects, we often encounter the following text box controls with id = "txtPrice" to dynamically add events to corresponding objects:
Now we add an event dynamically for it. The core JS Code is as follows:
Document. getElementById ("txtPrice"). attachEvent ('onblur'
In fact, the bind and unbind of events are prepared for custom events.Grammar:
$ (selector). Trigger (type, data);Action: Triggers a class of events on each matched element that triggers a custom event registered by bind ().Parameter explanation:
Type (String): Event type to be used for DharmaData (Array): Optional parameters, additional parameters passed to the event handler
Example:Add
").bind({ "click": function () { console.log("bind-obj:click1"); }, "click": function () { console.log("bind-obj:click2"); }, "click": function () { console.log("bind-obj:click3"); } });Two, the difference between the element binding eventFirst, the conclusion: by invoking the event name and bind in a way that binds only the elements that existed before, the added element cannot bind the event, while the delegate and on bind element
Different relationships between common field events and results and field events
In ASP. NET development, we may need to add, search, or update a common field. In addition, the buttons are separated independently. The event processing result is different. In this way, the relationship and results between them need to be coordinated in An ASPX webpage.Some netizens asked similar questions on the Internet:
I
Main reason: "$ (function () {XXX}") when registering a click event with the element on the page; ", JS dynamically generated elements have not yet been generated, so the click event does not take effectWorkaround:Scenario One:JS dynamically generated elements and then to register the event "registration event placed under the dynamically generated JS (JS is executed from the top down, when registering the event when the element has been generated, there will be no registration failure phenomeno
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.