2015-04-06 63 views
0

HTML:選擇選項2 「列」,儘管左側立柱上最長的長度以及對齊

<select name="timezones" id="timezones"> 
    <option value="1">Pacific/Auckland +12:00</option> 
    <option value="2">Australia/Brisbane +10:00</option> 
    <option value="3">Austrabane +10:00</option> 
    <option value="4">Australia +12:00</option> 
</select> 

JS:

var spacesToAdd = 5; 
var biggestLength = 0; 
$("#timezones option").each(function(){ 
var len = $(this).text().length; 
    if(len > biggestLength){ 
     biggestLength = len; 
    } 
}); 
var padLength = biggestLength + spacesToAdd; 
$("#timezones option").each(function(){ 
    var parts = $(this).text().split('+'); 
    var strLength = parts[0].length; 
    console.log(strLength); 
    for(var x=0; x<(padLength-strLength); x++){ 
     parts[0] += ' '; 
    } 
    $(this).text(parts[0].replace(/ /g, '\u00a0')+parts[1]); 
}); 

所以JS計算上的 「左」 列中最長的單詞,然後將空間到較短的其他列,以使右列良好對齊。它不工作,但經過一段時間的調試後,我找不到原因。

http://jsfiddle.net/ASR2K/352/

編輯:這是我的問題:http://screencast.com/t/MMs5sKWsD

+0

它似乎在小提琴上工作正常。究竟是什麼問題? –

+0

您的預期成果是什麼?從Chrome和IE瀏覽器中的jsfiddle中快速檢查,我看不到任何明顯的問題 –

+0

乍一看,它看起來像是將空白添加到最長的選項以及其他選項。嘗試通過檢查填充時的長度來跳過該部分。 – dartonw

回答

0

試戴FireFox和Chrome和兩個工作正常。

enter image description here

+0

奇怪的是,我得到這個:http://screencast.com/t/MMs5sKWsD –

+0

Safari瀏覽器? –

+0

Mac上的Chrome, –