2009-04-06 17 views

答えて

39

clickイベントのshiftKeyプロパティを見ることができます。

window.addEventListener("click", 
 
    function(e) { 
 
    if (e.shiftKey) console.log("Shift, yay!"); 
 
    }, 
 
    false);
<p>Click in here somewhere, then shift-click.</p>

2

DOMから発射されたイベントは、shiftKey(または同等)を含有するべきイベントが発生したときに、シフトキーの状態を示すプロパティ。例えば、を参照されたい。例としてhttps://developer.mozilla.org/en/DOM/event.shiftKey

YUI、Prototype、jQueryなどのJavaScript/DOMラッピングライブラリを使用している場合は、実装上の相違は問題にならないはずです。

3

関数のパラメータとしてeventを渡す必要があります。他のパラメータも渡すことができます。

<html> 
<head> 
    <script type="text/javascript"> 
     function doSomething(event, chkbox) 
     { 
      if (event.shiftKey) 
       alert('Shift key was pressed while picking ' + chkbox.value); 
      else 
       alert('You picked ' + chkbox.value); 
     } 
    </script> 
</head> 
<body> 
    <h3>Pick a Color</h3> 
    <input type="radio" name="myColors" onclick="doSomething(event, this)" value="Red" /> Red<br/> 
    <input type="radio" name="myColors" onclick="doSomething(event, this)" value="Green" /> Green<br/> 
    <input type="radio" name="myColors" onclick="doSomething(event, this)" value="Blue" /> Blue<br/> 
</body> 
</html> 
関連する問題