最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 正文

JS实现

来源:动视网 责编:小OO 时间:2025-10-02 10:48:51
文档

JS实现

AsweallknownthatwecanbindeveryfunctionasanactionPerformtoandocumentelementbythisway:document.getElementById(domId).onclick=FunctionMethod;It'sawonderfulimplementsthemodebettweninActionandListener.However,whatshouldwedoifwetypelogicframecodefordocume
推荐度:
导读AsweallknownthatwecanbindeveryfunctionasanactionPerformtoandocumentelementbythisway:document.getElementById(domId).onclick=FunctionMethod;It'sawonderfulimplementsthemodebettweninActionandListener.However,whatshouldwedoifwetypelogicframecodefordocume


As we all known that we can bind every function as an actionPerform to an document element by this way :

document.getElementById(domId).onclick = FunctionMethod;

It's a wonderful implements the mode bettwen in Action and Listener.

However , what should we do if we type logic frame code for document?

here is an example for you : MouseListener to do something when we apply MouseClick Action.

//Declare MouseListner Class

var MouseListener = {

//actionPerform method

actionPerform : function(){

alert("Hey , Mouse has action.");

}

}

//ActionSource

function MouseClick(listener){

if (listener.actionPerform && typeof listener.actionPerform === "function"){

listener.actionPerform();

}

}

//Test code

MouseClick(MouseListener);

/*

* output:

*window alert : Hey, Mouse has action.

*/

write by henry

--------------------------------------------------------------------------------------------------

就像我们所知道的,我们可以通过这样一个方法绑定每一个函数事件在一个dom元素上:

document.getElementById(domId).onclick = FunctionMethod;

这个方法完美的实现了动作和。

尽管如此,当我们为页面写逻辑框架代码时,我们应该怎么做?

这里有一个例子给你 :当我们触发鼠标点击事件时,鼠标做了些事情。

//声明鼠标类

var MouseListener = {

//动作触发函数

actionPerform : function(){

alert("Hey , Mouse has action.");

}

}

//事件源

function MouseClick(listener){

if (listener.actionPerform && typeof listener.actionPerform === "function"){

listener.actionPerform();

}

}

//测试函数

MouseClick(MouseListener);

/*

* 输出:

*窗口 弹出 : Hey, Mouse has action.

*/

write by henry

文档

JS实现

AsweallknownthatwecanbindeveryfunctionasanactionPerformtoandocumentelementbythisway:document.getElementById(domId).onclick=FunctionMethod;It'sawonderfulimplementsthemodebettweninActionandListener.However,whatshouldwedoifwetypelogicframecodefordocume
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top