var clickFunction = function(){ // 在这里添加事件发生时你要执行的任何代码 alert('this element now recognizes the click event'); } window.addEvent('domready', function() { $('id_name').addEvent('click', clickFunction); });
var mouseEnterFunction = function(){ // 在这里添加事件发生时你要执行的任何代码 alert('this element now recognizes the mouse enter event'); } window.addEvent('domready', function() { $('id_name').addEvent('mouseenter', mouseEnterFunction); });
var function = keydownEventFunction () { alert('This textarea can now recognize keystroke events'); }; window.addEvent('domready', function() { $('myTextarea').addEvent('keydown', keydownEventFunction); });
// 注意函数括号中的“event”参数 var keyStrokeEvent = function(event){ // 下面的代码是说: // 如果按下的键为“k”,则做下面的事 if (event.key == "k") { alert("This tutorial has been brought you by the letter k.") }; } window.addEvent('domready', function() { $('myInput').addEvent('keydown', keyStrokeEvent); });
var keyStrokeEvent = function(event){ // 下面的代码是说: // 如果按下的键为“k”,则做下面的事 if (event.key == 'k') { alert("This Mootorial was brought to you by the letter 'k.'") }; } var mouseLeaveFunction = function(){ // 在这里添加事件发生时你要执行的任何代码 alert('this element now recognizes the mouse leave event'); } var mouseEnterFunction = function(){ // 在这里添加事件发生时你要执行的任何代码 alert('this element now recognizes the mouse enter event'); } var clickFunction = function(){ // 在这里添加事件发生时你要执行的任何代码 alert('this element now recognizes the click event'); } window.addEvent('domready', function() { $('click').addEvent('click', clickFunction); $('enter').addEvent('mouseenter', mouseEnterFunction); $('leave').addEvent('mouseleave', mouseLeaveFunction); $('keyevent').addEvent('keydown', keyStrokeEvent); });
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn