2011-04-16 90 views
0

Hello 我需要做的是当我点击画布外的图像时调用一个javascript函数在HTML5画布上绘制一些东西。input type =“image”and input type =“button”to draw in html5 canvas,the button is working,but I need the image to working

当我使用一个按钮来做到这一点,它工作正常

<input type="button" id="xxx" onclick="draw()"/> 

但是当我使用的图像

<input type="image" id="xxx" onclick="draw()" src="file/sw1.gif"/> 

的问题是,当我点击图像它会打开一个新页面的东西看起来像 index.html?x=89&y=8 问题是我怎样才能使图像行为就像按钮,而无需打开新的页面? 谢谢

+0

更好地使用不透明度为0的图像和绝对定位输入 – 2013-07-24 19:03:23

回答

1

只需使用<img>标记代替图像输入,因为这不是它的目的。

0

你当然可以使用图像按钮在onclick事件上执行Javascript。我认为关键是要从form元素中删除actionid属性。这(诚然简单)的代码工作正常:

<!DOCTYPE html> 
<html> 
    <body> 
     <form> 
      <input type="image" value="Submit" onclick="doSomething();" src="html5.png"> 
     </form> 
     <script> 
      function doSomething() 
      { 
       alert("hi mom"); 
      } 
     </script> 
    </body> 
</html> 

测试与FF 5时,Chrome 12,Safari 5的,和(哇!)IE 9(Win7上)。

相关问题