我有一個顯示小紅球和JAVASCRIPT函數的CSS ID。我想在JavaScript函數中將CSS id作爲參數傳遞。我看過很多教程,但無法弄清楚。下面是代碼:將CSS ID作爲JavaScript函數中的參數傳入
CSS代碼
#projectile{
position: absolute;
background-color: #ff0000;
left:176px;
top: 486px;
width:10px;
height:10px;
border-radius: 8px;
z-index: 9;
}
JavaScript代碼
function gofish(projectile_id){
var projectile = getElementbyId(projectile_id);
start_x = projectile.offset().left;
start_y = projectile.offset().top;
function init()
{ setTimeout("gofish('projectile')", 500); }
你有一個'getElementbyId'函數,或者你實際上是否指'document.getElementbyId' – adeneo
它看起來像你使用'offset()'f中的jQuery聯合? – adeneo
打開瀏覽器控制檯,您會發現查看錯誤消息很有用。 – jdigital