2016-06-07 59 views
1

我試圖在按鈕之間添加空間,我已經找到了方法,但我找不到我正在尋找的東西。如何在按鈕之間添加空間?

for (i=0;i<res.length;i++) { 
    var newbutton = document.createElement("BUTTON"); 
    var t = document.createTextNode(" "+res[i]); 
    newbutton.appendChild(t); 
    document.body.appendChild(newbutton); 
} 

我想從最終結果的按鈕之間放置空間。 我想我必須使用setattribute,但不知道如何以及在哪裏。 預先感謝您。 :)

+2

您應該使用CSS這一點。 – Marcus

+0

我懂了!謝謝:) –

回答

3

使用CSS這樣的東西。添加一個右頁邊距會做你問什麼...

var res = ["button1", "button2", "button3", "button4"]; 
 

 
for (i=0;i<res.length;i++) { 
 
    var newbutton = document.createElement("BUTTON"); 
 
    var t = document.createTextNode(" "+res[i]); 
 
    newbutton.appendChild(t); 
 
    document.body.appendChild(newbutton); 
 
}
button { 
 
    margin-right: 10px; 
 
}

+0

謝謝!!!!我真的很感激!! :) –

+0

沒問題。很高興幫助:) – Archer

0

你可以使用保證金爲:

for (i=0;i<res.length;i++) { 
    var newbutton = document.createElement("BUTTON"); 
    var t = document.createTextNode(" "+res[i]); 
    newbutton.appendChild(t); 
    newbutton.style.marginRight = "5px"; 
    document.body.appendChild(newbutton); 
} 
+0

WOW。它工作完美!謝謝!!! :) –

+0

@hwanheeYi不客氣:) –

相關問題