Αναζήτηση στην υποστήριξη

Προσοχή στις απάτες! Δεν θα σας ζητήσουμε ποτέ να καλέσετε ή να στείλετε μήνυμα σε κάποιον αριθμό τηλεφώνου ή να μοιραστείτε προσωπικά δεδομένα. Αναφέρετε τυχόν ύποπτη δραστηριότητα μέσω της επιλογής «Αναφορά κατάχρησης».

Learn More

event.button

  • 2 απαντήσεις
  • 1 έχει αυτό το πρόβλημα
  • 2 προβολές
  • Τελευταία απάντηση από keithprice900533

more options

why does this not work in FF <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> <script> function mouseButton(e) { alert(event.button); } </script> <input name="Button" type="radio" value="1" onmousedown="mouseButton(this);">

why does this not work in FF <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <script> function mouseButton(e) { alert(event.button); } </script> </head> <body> <input name="Button" type="radio" value="1" onmousedown="mouseButton(this);" /> </body> </html>

Όλες οι απαντήσεις (2)

more options

The short answer is, "because the event object is not defined." Unlike IE, Firefox doesn't attach events to the global window object. Instead, it is passed to the function. You could try something like this:


<!DOCTYPE html> <html> <head> <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type"> <script type="text/javascript"> function mouseButton(e){ if (!e) e = window.event; var tgt = (e.target) ? e.target : e.srcElement; if (e.which){ // not IE switch (e.button){ case 0: var btn = "left"; break; case 1: var btn = "middle"; break; case 2: var btn = "right"; } } else { // IE switch (e.button){ case 1: var btn = "left"; break; case 4: var btn = "middle"; break; case 2: var btn = "right"; } } alert(btn + " mouse button down on " + tgt.nodeName + "#" + tgt.id); } window.onload = function(){ document.getElementById("rad1").onmousedown = mouseButton; } </script> </head> <body> <p><input type="radio" name="button" value="1" id="rad1"></p> </body> </html>

Note: because different browsers return different values for e.button, I'm not sure this is 100% reliable. You probably can find better code for sorting out the button value.

more options

As you may have guessed what I needed was much more complex than this, but with your post I have been able to do what I needed, thank you very much for your help. All the best Keith