2009-07-08 91 views
0

我有一个3 x 3单元格的表格。每个单元格在1-9中都包含一个按钮,当单击任何按钮时,该值将被附加到输入文本框中。如何触发此事件?

我试图触发表中的onmouseout事件,但没有奏效。我还尝试在表格外添加一个div,以捕捉onmouseout事件。

如何使用JavaScript触发客户端游标是否仍在桌子上?

我想要的是在用户单击按钮中的某些内容并且鼠标离开了表格之后,我需要验证客户端单击的内容。

+0

你想追加按钮单击单元格的值吗? – rahul 2009-07-08 06:05:24

+0

“我需要验证客户端点击了什么”。这是什么意思?请在您的问题中提供更多信息。 – rahul 2009-07-08 06:27:39

回答

0

如果您在表上设置OnMouseout事件,则当您将光标移动到表中的某个对象上时,将会触发它,因为光标不再直接位于表上。

我不确定你想在这里做什么。当你点击一个按钮时你想提出一个事件还是你想在光标移动到桌子外面时引发一个事件?

编辑:
下面的代码会在每次单击按钮时引发一个事件。
的myClickEvent功能会知道哪个按钮被点击:

<html> 
    <head> 
    <script> 
     function myClickEvent(obj) { 
     document.getElementById("myTextBox").value += obj.value; 
     } 
    </script> 
    </head> 
    <body> 
    <table> 
     <tr> 
     <td><input type="button" value="1" onClick="myClickEvent(this);"></input></td> 
     <td><input type="button" value="2" onClick="myClickEvent(this);"></input></td> 
     <td><input type="button" value="3" onClick="myClickEvent(this);"></input></td> 
     </tr> 
     <tr> 
     <td><input type="button" value="4" onClick="myClickEvent(this);"></input></td> 
     <td><input type="button" value="5" onClick="myClickEvent(this);"></input></td> 
     <td><input type="button" value="6" onClick="myClickEvent(this);"></input></td> 
     </tr> 
     <tr> 
     <td><input type="button" value="7" onClick="myClickEvent(this);"></input></td> 
     <td><input type="button" value="8" onClick="myClickEvent(this);"></input></td> 
     <td><input type="button" value="9" onClick="myClickEvent(this);"></input></td> 
     </tr> 
    </table> 
    <input type="text" id="myTextBox"></input> 
    </body> 
</html> 
0

尝试添加onmouseout事件为要验证,你也可以使用悬停css样式,解决了控制。