Discussion on jquery event processing

Source: Internet
Author: User

discussion on jquery event processing

In a front-end development system based on jquery, many events are often bundled on one page through various identities. Even if the simple use of the event agent, but also caused the dispersion of events, bad maintenance and management.

So, how to solve this problem? And I thought about the events in backbone. As follows:

The code is as follows:

Events: {

"Click. Icon": "Open",

"Click. Button.edit": "Openeditdialog",

"Click. Button.delete": "Destroy"

}

That is, bringing events together, similar to a concept in the event-processing center.

Simple to cut the realization of the idea:

Bind the event to the body node by using the event agent. (some events themselves are not bubbling, do not do research for the time being)

For the execution object of the event, give a uniform identity.

The execution function of the event, centralized processing.

The code is as follows:

  

  

 

  

 

  

Event Processing Center

var clickeventcenter = {

' Handler1 ': function () {

Do something ...

},

' Handler2 ': function () {

Do something ...

}

// ...

}

Event Bindings

$body. On ("click", "[Data-click-center]", function () {

var HandlerName = $ (this). Data ("Click-center");

var handler = Clickeventcenter[handlername]

if ($.isfunction (handler)) handler ()

})

In this case, one type of event is lumped together.

At some point, it can play a very good role.

The above mentioned is the entire content of this article, I hope you can enjoy.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.