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); });
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn