Home > Web Front-end > JS Tutorial > js and jquery batch binding event passing parameters 1 (new pig original)_javascript skills

js and jquery batch binding event passing parameters 1 (new pig original)_javascript skills

WBOY
Release: 2016-05-16 18:24:32
Original
1179 people have browsed it
Copy code The code is as follows:






The following is the code combined with jquery, the principle is the same
When using javascript to batch bind elements on the page and pass the incremental number, you need to write as follows: Code for the
part:
Copy code The code is as follows:

< ;input type="button" id="btn1" value="Button 1" />

< ;input type="button" id="btn3" value="Button 3" />

< ;input type="button" id="btn5" value="Button 5" />

< ;input type="button" id="btn7" value="Button 7" />

Part of the code:
Copy code The code is as follows:

$(function () {
var i;
for (i = 1; i < = 7; i ) {
$("#btn" i).bind("click", { id: i }, dis);
}
});

function dis(evt) {
alert(evt.data.id);
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template