onmouseup 事件

定义和用法

onmouseup 事件会在鼠标按键被松开时发生。

语法

  1. onmouseup="SomeJavaScriptCode"
参数 描述
SomeJavaScriptCode 必需。规定该事件发生时执行的 JavaScript。

支持该事件的 HTML 标签:

  1. <a>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <body>, <button>,
  2. <caption>, <cite>, <code>, <dd>, <dfn>, <div>, <dl>, <dt>, <em>, <fieldset>,
  3. <form>, <h1> to <h6>, <hr>, <i>, <img>, <input>, <kbd>, <label>, <legend>,
  4. <li>, <map>, <ol>, <p>, <pre>, <samp>, <select>, <small>, <span>, <strong>,
  5. <sub>, <sup>, <table>, <tbody>, <td>, <textarea>, <tfoot>, <th>, <thead>,
  6. <tr>, <tt>, <ul>, <var>

支持该事件的 JavaScript 对象:

  1. button, document, link

实例 1

在本例中,在点击图片并松开鼠标按键后,将显示一个对话框:

  1. <img src="/i/eg_mouse2.jpg" alt="mouse"
  2. onmouseup="alert('您点击了图片!')" />

输出:(请点击图片):

Visit!

实例 2

在本例中,对话框中会显示出您所点击的元素的标签名:

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function whichElement(e)
  5. {
  6. var targ
  7. if (!e) var e = window.event
  8. if (e.target) targ = e.target
  9. else if (e.srcElement) targ = e.srcElement
  10. if (targ.nodeType == 3) // defeat Safari bug
  11. targ = targ.parentNode
  12. var tname
  13. tname=targ.tagName
  14. alert("You clicked on a " + tname + " element.")
  15. }
  16. </script>
  17. </head>
  18.  
  19. <body onmouseup="whichElement(event)">
  20.  
  21. <h2>This is a header</h2>
  22. <p>This is a paragraph</p>
  23. <img border="0" src="ball16.gif" alt="Ball">
  24.  
  25. </body>
  26. </html>