用這是我的javascript代碼的Javascript:初始化變量之外的功能和內部功能
var helper = document.getElementById("helper");
helper.style.position = "relative";
helper.style.width = "50px";
helper.style.height = "50px";
helper.style.border = "1px solid #000";
function move() {
helper.style.left = event.offsetX + "px";
helper.style.top = event.offsetY + "px";
}
和我的html代碼
<div id="grid" onmousemove="move()" onmousedown="down()">
<div id="helper"></div>
</div>
但是當我調用該函數沒有任何反應。我想該變量幫手BI全球和一切預初始化,所以我不必從頭再來初始化一切,當函數被調用
[爲什麼jQuery或DOM方法(例如\'getElementById \'找不到元素?])(http://stackoverflow.com/questions/14028959/why-does-jquery-or-a- dom-method-such-as-getelementbyid-not-find-the-element) – Bergi 2013-02-17 12:49:16