1

私は少し初心者ですが、明らかなことはすべて試しました。おそらく、私の JavaScript はひどいので、それが理由ですが、onmousedown = func; 動作しません。等

    function performCommand(event)
{
    /*removed*/
//It reaches this point
        document.body.onclick = function() { 
        //Never reaches this point
/*removed*/
    }
}
4

1 に答える 1

0

https://developer.mozilla.org/en/DOM/element.onclick

概要

onclick プロパティは、現在の要素の onClick イベント ハンドラー コードを返します。

構文

element.onclick = functionRef;

ここで、functionRef は関数です。多くの場合、別の場所で宣言された関数の名前または関数式です。詳細については、コア JavaScript 1.5 リファレンス:関数を参照してください。

<!doctype html>
<html>
<head>
<title>onclick event example</title>
<script type="text/javascript">
function initElement()
 {
 var p = document.getElementById("foo");
 // NOTE: showAlert(); or showAlert(param); will NOT work here.
 // Must be a reference to a function name, not a function call.
 p.onclick = showAlert;
 };

function showAlert()
 {
 alert("onclick Event detected!")
 }
</script>
<style type="text/css">
#foo {
border: solid blue 2px;
}
</style>
</head>
<body onload="initElement()";>
<span id="foo">My Event Element</span>
<p>click on the above element.</p>
</body>
</html>

または、次のように無名関数を使用できます。

p.onclick = function() { alert("moot!"); };

( MDC @cc-by-saより)

于 2010-08-20T16:20:14.290 に答える