2011-07-20 34 views
0

我的腳本中有以下代碼來爲每列設置最大高度。 但是,我打算單獨設置所有4列每行的最大高度。 目前它不會執行每個類的功能。JavaScript和PHP每類的列高度

這裏的JavaScript的:

<script type="text/javascript" > 
$(document).ready(function() { 

<?php 
$test = $cart->count_contents(); 
for ($i=0, $n=$test; $i<$n; $i++) { 
?> 
setHeight('.<?php echo 'col'.$i; ?>'); 
<?php 
    } 
?> 

}); 


//Initialize the global variable, this will store the highest height value 
var maxHeight = 0; 


function setHeight(col) { 



//Get all the element with class = col 
col = $(col); 

//Loop all the col 
col.each(function() { 

//Store the highest value 
if($(this).height() > maxHeight) { 
maxHeight = $(this).height();; 
} 
}); 

//Set the height 
col.height(maxHeight); 
} 
</script> 

我從MySQL數據庫和PHP,拉出各行產生下面的HTML:

<div class="ui-grid-c ui-bar ui-bar-e"> 
<div class="ui-block-a"><div class="ui-bar ui-bar-b" style="height: 20px;">Remove</div></div> 

<div class="ui-block-b"><div class="ui-bar ui-bar-b" style="height: 20px;">Product(s)</div></div> 
<div class="ui-block-c"><div class="ui-bar ui-bar-b" style="height: 20px;">Qty.</div></div> 
<div class="ui-block-d"><div class="ui-bar ui-bar-b" style="height: 20px;">Total</div></div> 

<div class="ui-block-a"><div class="ui-bar ui-bar-c col0"><input type="checkbox" name="somename1" value="somevalue1"></div></div> 



<div class="ui-block-b"><div class="ui-bar ui-bar-c col0"><a href="#"><img src="images/someimage1.gif" border="0" alt="sometitle1" title="sometitle1" width="100" height="80"></a> 
<a href="#"><b>sometitle1</b></a><br><small><i - >somecontent</i></small><br><small><i> - somecontent</i></small><br><small><i> - somecontent</i></small></div></div> 

<div class="ui-block-c"><div class="ui-bar ui-bar-c col0"><input type="text" name="somename1" value="1" size="4"></div></div> 
<div class="ui-block-d"><div class="ui-bar ui-bar-c col0"><b>sometext1</b></div></div> 


<div class="ui-block-a"><div class="ui-bar ui-bar-c col1"><input type="checkbox" name="somename2" value="somevalue2"></div></div> 



<div class="ui-block-b"><div class="ui-bar ui-bar-c col1"><a href="#"><img src="images/someimage2.gif" border="0" alt="sometitle2" title="sometitle2" width="100" height="80"></a><a href="#"><b>sometitle2</b></a></div></div> 
<div class="ui-block-c"><div class="ui-bar ui-bar-c col1"><input type="text" name="somename2" value="1" size="4"></div></div> 
<div class="ui-block-d"><div class="ui-bar ui-bar-c col1"><b>sometext1</b></div></div> 


</div><!-- /grid-a --> 
+0

我通過把固定的問題:VAR maxHeight = 0;在函數內而不是函數的上面 – wHiTeHaT

回答

0

問題不回答自己合適的位置,我會複製你的解決方案

你只需要改變:

//Initialize the global variable, this will store the highest height value 
var maxHeight = 0; 


function setHeight(col) { 
// etc etc etc 

到:

function setHeight(col) { 
var maxHeight = 0; 
//etc etc etc 
0

我只需要改變:

//Initialize the global variable, this will store the highest height value 
var maxHeight = 0; 


function setHeight(col) { 
// etc etc etc 

到:

function setHeight(col) { 
var maxHeight = 0; 
//etc etc etc 
相關問題