js / jq about js / jq click event, and get the value

1, at present, personally think the most convenient click event is onclick () event method call, not only traditional values, but also to avoid some unnecessary trouble:

Page code:

< Div onclick = "thisOnClick (the this)" the above mentioned id = "test (ID)" of the type = "test (of the type)" the Data-of the type = "test (the Data-of the type)" > 
    click me 
</ div >

js code:

function thisOnClick (E) { 
    the console.log ( "acquired the current ID:", e.id); // get the value defined ID 
    console.log ( "acquired the type currently defined:", e.getAttribute ( " type ")); // Get type: type value defined 
    console.log (" acquired the data-type currently defined: ", e.getAttribute (" data-type ")); // Get data-type defined value 
    console.log ( "acquired current-defined type Data:", e.dataset.type); // Data-type (HTML5) 
}

 

2, and the use of class or use id to bind the click event, commonly used as follows:

3, but when the html is dynamically generated using a class or using wording click event id that will be another way:

Guess you like

Origin www.cnblogs.com/caitangbutian/p/11489366.html