<script type="text/javascript">
$(document).ready(function(){ /***加载事件的开始,这行就不别改了!**/
document.getElementById("one").onmouseenter=show;
function show()
{console.log( '********' );}
}) /***加载事件的结束,这行就不别改了!**/
</script>
<body>
<div id="one"></div>
<div onmouseenter="show()" id="two" ></div> //★★就是这个地方,提示:"Uncaught ReferenceError: show is not defined"
<body>
就是★★的地方,提示:"Uncaught ReferenceError: show is not defined"
我要是把
$(document).ready(function(){ /***加载事件的开始,这行就不别改了!**/
删了,第一个 <div> 又不管事了...
楼主应该这样写吧
如果你定义在reday里面的function实际上这是一个私有
作用域
,show只能在function() {}里面使用;而two绑定的函数必须是在全局中可以调用到。