2013-02-15 76 views
1

我正在制作一个JavaScript迷宫游戏,并且为了在到达墙壁时停止角色,我需要使用if...else语句来检测单元格边框。例如:Javascript检测表单元格边框?

var blah = document.getElementById('hi').style.border-right; 

if(blah==20px) { 
    my function 
} 

这可能吗?如果是这样,那么怎么样?谢谢!

+1

使用'borderRight' – 2013-02-15 04:46:28

+0

这将工作? – 2013-02-15 04:49:53

+0

我不知道,但它会让你'id = hi'元素的'border-right'风格值 – 2013-02-15 04:50:21

回答

0
function getBorders(el) 
{ 
    return ["Top", "Right", "Bottom", "Left"].map(
     function(v) { return el.style["border"+v+"Width"]; }); 
} 

var b = getBorders(document.getElementById('hi')); 
// b is an array with border-width strings (or empty strings) 
// in the css order top, right, bottom, left——access with subscripts 0-3 
+0

我可以理解这是干什么的,但是如何将它添加到我的代码中?我的例子是在http://thomaswd.com/maze。 – 2013-02-15 07:10:58