Home > Web Front-end > JS Tutorial > js dynamically adds events and can pass parameters sample code_javascript skills

js dynamically adds events and can pass parameters sample code_javascript skills

WBOY
Release: 2016-05-16 17:19:20
Original
1396 people have browsed it
Copy code The code is as follows:

var tt=function(obj)
{
return function()
{
alert(obj.tagName); //It can be an execution function defined externally;
}
}
function addfunction()
{
var bigobj=document.getElementById("mytable");
var rows =bigobj.rows;
for(var j=0; j{
for(var i=0;i{
rows[j].cells[i].attachEvent("onmousemove",tt(rows[j].cells[i ]));
//rows[j].cells[i].onmousemove = function(){
// tt();
//}
}
}
}

========== Compatible with FF and IE writing
Copy code The code is as follows:

function addEvent (o,c,h){
if(o.attachEvent){
o.attachEvent('on' c,h);
}else{
o.addEventListener(c,h,false);
}
return true;}
var tt=function(obj)
{
return function (){textChange(obj);}
}
addEvent(input1,"change",tt(input1));
function textChange(o)
{

// do something

}

Use Jquery to do it in one sentence
$("input[type='text']").change( function() {
// You can write some verification code here
});
Related labels:
js
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