我想創建一個郵票表單/預覽的網站,我很新的JavaScript。我正在爭取讓邊框px以與顏色選擇框中相同的顏色顯示。顯示/隱藏包含div的邊框嗎? Javascript
的JavaScript是:
function setColor() {
var color = document.getElementById("color").value;
document.getElementById("myDiv").style.color = color;
}
function border(border) {
document.getElementById("myDiv").style.border = border;
}
是的div的CSS如下:
#myDiv {
position:relative;
width:100px;
height:100px;
float:left;
overflow:hidden;
border:1px solid #f1f1f1;
text-align:center;
}
#lineOne {
position:relative;
padding:5px;
}
#lineTwo {
position:relative;
padding:5px;
}
#lineThree {
position:relative;
padding:5px;
}
#lineFour {
position:relative;
padding:5px;
}
和HTML像這樣:
Colour:
<select id="color" onclick="setColor();">
<option value="white">white</option>
<option value="black" selected="selected">black</option>
<option value="red">red</option>
<option value="lightblue">light blue</option>
<option value="darkblue">dark blue</option>
<option value="lightgreen">light green</option>
<option value="darkgreen">dark green</option>
<option value="yellow">yellow</option>
<option value="orange">orange</option>
<option value="pink">pink</option>
<option value="purple">purple</option>
<option value="gray">gray</option>
</select>
<select id="border" onchange="border(this.value);">
<option value="1px solid" selected="selected">1px</option>
<option value="2px solid">2px</option>
<option value="3px solid">3px</option>
<option value="4px solid">4px</option>
<option value="5px solid">5px</option>
</select>
<div id="myDiv>
<div id="lineOne">Some text here</div>
<div id="lineTwo">Mores text here</div>
<div id="lineThree">And even more</div>
<div id="lineFour">And last text here</div>
請你能告訴我怎麼更改邊框像素以及將邊框顏色更改爲顏色下拉選擇的邊框顏色。
順便說一句,你在'myDiv'旁邊缺少''''。 – 2012-02-04 13:56:19