0
我正在創建輸入字段,我希望它們每次在for循環開始時都對齊左側。我怎麼能做到這一點?如何對齊動態輸入字段?
HTML
<form name="myform1">
<select id="polja2" onchange="Gen()">
<option value="1">1</option>
<option value="2">2</option>
</select>
</form>
<form name="myform">
<select id="polja" onchange="Gen()">
<option ></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</form>
<form>
<div id="t">
</div>
<input type="button" value="Unesite vrijednosti" onclick="korekcija(this.form)">
</form>
的JavaScript
function Gen()
{
var val = document.getElementById("polja");
val=(val.options[val.selectedIndex].value);
var valGrup = document.getElementById("polja2");
valGrup=(valGrup.options[valGrup.selectedIndex].value);
var i;
var j;
var e = document.getElementById("t");
var randomColor;
for(i=0;i<valGrup;i++) {
randomColor="#"+(Math.random()*0xFFFFFF<<0).toString(16);
generate(e, i,randomColor,j,val);
}
}
function generate(e, i,randomColor,j,val) {
e.innerHTML += "Grupa: "+i+"<br>";
e.innerHTML += "<input type='color' name ='color1' value='"+randomColor+"' id='color"+i+"'/>"+"<br>" ;
e.innerHTML += "<input type='text' id='naziv" +i+"'/>"+"<br>";
for(j=0;j<val;j++) {
e.innerHTML += "<input type='number' id='inputpolja"+i+j+"'/>"+"<br>";
}
}
我嘗試添加靠左對齊,在div標籤,但沒有奏效。
全屏JSFIDDLE次修改後的代碼你希望他們旁邊對準彼此? – 2014-10-20 17:37:19
好耶,這是一個普遍的想法 – sritno 2014-10-20 17:39:34