可能重复:
我使用的是Box2dJS库,它使用的是原型,因此我必须包括原型库才能工作。我没有在我的主脚本中使用任何原型代码,只有Box2d对象使用原型。我在脚本中使用JQuery,由于我包含了prototype,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)库时,一切正常。我怎么才能解决这个问题?
发布于 2011-07-10 21:53:46
从您提供的代码片段中,您可能希望在box2dutils库之前重新排序加载jQuery库。可能是box2dutils劫持了这些事件或与jQuery发生冲突
发布于 2011-07-10 21:47:38
很可能它们不兼容,你必须两者兼用吗?
https://stackoverflow.com/questions/6643835
复制相似问题