2013-04-05 39 views
0
if(boothsizerGlobal == 3){ 
    var cellWidth = 112; 
    var cellHeight = 52; 
    var innerDivElectricTop = 41; 
    var innerDivElectricLeft = 110;  
    $('.imgBox').css("background-image", "url(booth_top_images/5X20TOP.jpg)"); 
    $('.imgBox').css("width", "900px"); 
    $('.imgBox').css("height", "225px"); 
    sidewalls = 2; 
    backwalls = 6; 

} 

任何人都可以幫助我將以上代碼轉換爲PHP嗎? 我的意思是如何在40多個條件下爲DIV設置CSS?在PHP中包含DIV的CSS

感謝

+0

將javascript轉換爲php?他們都有不同的工作。服務器!=瀏覽器 – 2013-04-05 10:06:01

+0

你沒有使用'cellWidth'或'cellHeight' ... – 2013-04-05 10:08:10

+0

如果你真的想,你可以使用['switch'](http://www.javascriptkit.com/javatutors/switch .shtml) - 在JavaScript中聲明。更好地使用比各種'if'語句... – 2013-04-05 10:09:57

回答

0

嘛,你原來的代碼沒有意義,開始與作爲甚至沒有被使用的聲明的變量的一半。此外,它超出了我爲什麼你想要將前端代碼轉換成這樣的服務器端代碼,php不是正確的方式來做到這一點!

if(boothsizerGlobal == 3){ 
    $cellWidth = '112px'; 
    $cellHeight = '52px'; 
    $innerDivElectricTop = '41px'; 
    $innerDivElectricLeft = '110px';  
    $backgroundImage = 'url(booth_top_images/5X20TOP.jpg)'; 

    $divCode = '<div style="width: ' . $cellWidth . '; height: ' . $cellHeight . '; "'; 
    return $divCode 

} 
+0

感謝它對我有用 – Dhar 2013-04-05 11:05:26

+0

@Dhar沒有問題,樂於幫助。 – 2013-04-05 11:06:24

1
.imgBox 
{ 
background:url(booth_top_images/5X20TOP.jpg) no-repeat; 
width:900px; 
height:225px; 
}