Two ways: directly add events to objects, add events to nodes
For example, add an onclick event to an ID with tab1
The first case:
var t = document.getElementById("tab1");
t.onclick = function tst(){
alert ('');
}
Second case
var tb = document.getElementById("tab1");
if(window.addEventListener){ // Mozilla, Netscape, Firefox
td_value.addEventListener('click', alert('11'), false);
td_value.addEventListener('click', alert('12'), false);
} else { // IE
td_value.attachEvent('onclick' , function(){alert('21');});
td_value.attachEvent('onclick', function(){alert('2'2);});
}
Statement: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