Rumah >hujung hadapan web >html tutorial >利用JS和CSS的覆盖特性来解决文件冲突问题_html/css_WEB-ITnose
<script type="text/javascript" src="a.js"></script><script type="text/javascript" src="b.js"></script>
a.js的文件内容:
window.onload=function(){alert("这是a.js的");}
window.onload=function(){alert("这是b.js的");}
<pre name="code" class="html"><script type="text/javascript" src="a.js"></script><script type="text/javascript"></script>
<span style="font-family: Arial, Helvetica, sans-serif;">var aa=window.onload;//得到已经定义的</span><span style="font-family: Arial, Helvetica, sans-serif;">window.onload事件处理程序的句柄或者说引用 这里面保存了a.js定义的</span><span style="font-family: Arial, Helvetica, sans-serif;">window.onload事件的逻辑操作。</span>
<span style="font-family: Arial, Helvetica, sans-serif;">window.onload=null;//把</span><span style="font-family: Arial, Helvetica, sans-serif;">window.onload的事件处理程序注销,这样系统就不会再执行</span><span style="font-family: Arial, Helvetica, sans-serif;">window.onload函数了。</span>
<span style="font-family: Arial, Helvetica, sans-serif;"></span>
<script type="text/javascript" src="b.js"></script><script type="text/javascript"></script>
<pre name="code" class="html"><span style="font-family: Arial, Helvetica, sans-serif;">var bb=window.onload;//得到已经定义的</span><span style="font-family: Arial, Helvetica, sans-serif;">window.onload事件处理程序的句柄或者说引用 这里面保存了b.js定义的</span><span style="font-family: Arial, Helvetica, sans-serif;">window.onload事件的逻辑操作。</span>
<span style="font-family: Arial, Helvetica, sans-serif;">window.onload=null;//把</span><span style="font-family: Arial, Helvetica, sans-serif;">window.onload的事件处理程序注销,这样系统就不会再执行</span><span style="font-family: Arial, Helvetica, sans-serif;">window.onload函数了。</span>
window.onload=function(){aa();bb();//重新注册<span style="font-family: Arial, Helvetica, sans-serif;">window.onload事件,执行的代码逻辑为a.js和b.js中定义的代码操作。</span>}