zoukankan      html  css  js  c++  java
  • javascript给不能修改的函数增加额外处理的方法

    不知道是否可行,但姑且google之。 查看到相关的stack overflow(堆栈溢出)帖子:http://stackoverflow.com/questions/1659219/add-to-a-javascript-function 代码拷贝如下: var originalFn = addToMe;addToMe =function(){  originalFn();// call the original function// other stuff}; addToMe =function(){  originalFn.apply(this, arguments);// preserve the arguments// other stuff}; addToMe =(function(originalFn){returnfunction(){    originalFn.apply(originalFn, arguments);// call the original function// other stuff};})(addToMe);// pass the reference of the original function 时间太晚,只试了一下第一种最简单的无参数的复写: 
    <html>
    <head>
    	<title>test</title>
    	<script type="text/javascript" src="jquery.js"></script>
    	<script type="text/javascript">     
        
        $(document).ready(function(){
        	$(":input[type='hidden']").bind("propertychange",function(){
        		alert($(this).val())
        	});
        });
        
        function addRow0(){
        	alert("simple ");
        }     
    </script>
    </head>
    <body>
    	<form>
    		<input id="hf" type="hidden" value="" />
    		
    		<input type="button" value="test" onclick="$('#hf').val('fire')" />
    		<input type="button" value="add hidden field" onclick="" />
    		<input type="button" value="cache that" onclick="addRow0()" />
    	</form>
    </body>
    <script type="text/javascript">
    	function addHidden(){
    		$("body").after("<input type='hidden' id='hf1' />");
    	}
    	var originalFn = addRow0;
    	addRow0 = function () {
          originalFn();
          alert(" is the best");
      }
    </script>
    </html>
    

      

    小伙伴们,有需要可以拿走玩一下。
  • 相关阅读:
    5.Spring高级装配(根据profile的激活状态决定使用的环境) 以及 条件化 Bean
    4.SpringJunit4ClassRunner
    3.Spring配置可选方案
    2.Spring容器bean的生命周期
    1.使用spring上下文容纳你的Bean
    maven 打包跳过 Junit test
    HTML5中meta name="viewport"
    二、JavaScript this
    VIM_插件
    VBS_DO...Loop
  • 原文地址:https://www.cnblogs.com/rain64531264/p/3681998.html
Copyright © 2011-2022 走看看