Home > Web Front-end > JS Tutorial > body text

In-depth explanation of js overwriting original methods and providing rewriting methods

亚连
Release: 2018-05-17 10:17:43
Original
3946 people have browsed it

If you make an editor, which provides some cursor leave events, etc., it is best to use this method to operate, because When others use your editor, they may need to use the event methods provided by the editor to handle some things. Some of the events need to be rewritten according to special requirements. Therefore, when this happens, provide the event method that allows the rewriting of the events provided by the editor. Method is very necessary!

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<script> 
    function myblur () { 
        alert("1、离开"); 
    } 
    function bindEvent(func){ 
        myblur = func; 
    } 
    function myonclick() { 
        bindEvent(function(){ 
            alert("天啊!myblur方法被覆盖了!"); 
        }); 
    } 
</script> 
</head> 
<body> 
<input type="text" onblur="myblur()" value="光标选中然后光标离开会调用myblur()方法"/> 
<input type="button" onclick="myonclick()" value="覆盖myblur()" /> 
注:覆盖myblur()后,再次光标选中输入框然后再离开 
</body> 
</html>
Copy after login

Purpose: To improve the perfect calling method.

The above is the js I compiled for everyone to cover the original method and provide a rewriting method. I hope it will be helpful to everyone in the future.

Related articles:

javascript simulated overloading, detailed answers to rewriting the toString method

Detailed explanation of JS rewriting Writing prototype objects

Detailed explanation of overwriting and overloading techniques of js methods

The above is the detailed content of In-depth explanation of js overwriting original methods and providing rewriting methods. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!