Such a requirement, if implemented with the live () method, is simple and easy to understand.
- $(' nav li, #sb-nav Li, #help li '). Live(' click ', function () {
- //code ...
- });
After the 1.7 version of jquery, we recommend that you replace the previous bind, live, and delegate methods with the on method.
How do you write the above sentence if it is on?
actually see live source code to know that live is actually entrusted doucment for event delegation.
According to this idea, you can bind the on method to the document.
- $(document). On(' click ', ' #header. Fixed-feedback-bn, #sb-sec feedback-bn ', function () {
- //code ...
- });
In another case, the on () method binds multiple events and can be written like this:
- $("Table.planning_grid"). On({
- MouseEnter: function() {
- //Handle MouseEnter ...
- },
- MouseLeave: function() {
- //Handle MouseLeave ...
- },
- Click: function() {
- //Handle click ...
- }
- }, "TD");
Finally, multiple selectors are bound with the On () method, and multiple events can be written like this:
- $(document). On({
- MouseEnter: function() {
- //Handle MouseEnter ...
- },
- MouseLeave: function() {
- //Handle MouseLeave ...
- },
- Click: function() {
- //Handle click ...
- }
- }, ' #header. Fixed-feedback-bn, #sb-sec feedback-bn ');
Http://www.qingdou.me/1536.html
The On () method of the jquery event binds multiple selectors, multiple events