可能重复:
jQuery 和 Prototype 事件
我正在使用 Box2dJS 库,它使用原型,所以我必须包含原型库才能使其工作。我没有在我的主脚本中使用任何原型代码,只有 Box2d 对象使用原型。我在我的脚本中使用 JQuery,因为我包含了原型,所以 jQuery 事件似乎没有触发。
这是相关的JS代码:
$.noConflict();
jQuery(document).ready(function(){
init();
});
function init(){
//add event handler to surrounding DIV to monitor mouse move and keystrokes
jQuery("#container").keypress(function(e){
keys[e.keyCode] = true;
alert("key pressed!");
});
jQuery("#container").keydown(function(e){
keys[e.keyCode] = true;
});
jQuery("#container").keyup(function(e){
keys[e.keyCode] = true;
alert("Key released!");
});
}
这是html代码:
<html>
<head>
<title>Box2D Test</title>
<!--[if IE]><script src="lib/excanvas.js"></script><![endif]-->
<script src="lib/prototype-1.6.0.2.js"></script>
<!-- box2djs scripts here-->
</head>
<body>
<center>
<div id="container" style="border:1px solid; cursor:none; width:600px; height:400px;">
<canvas id="canvas" width="600" height="400" >
Could not create Canvas!
</canvas>
</div>
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
<script src='js/box2dutils.js'></script>
<script type="text/javascript" src="main.js"></script>
</center>
</body>
</html>
没有任何警报响起,但是当我删除原型(和 box2d)库时,一切正常。我怎样才能解决这个问题?