你好我是非常新的HTML和Javascript.Im尝试创建提示,用户能够输入颜色,他们希望寄宿生改变其边框颜色。任何人都可以帮助我解决这个问题,请指出我需要什么,在哪里。谢谢所有能够帮助的人 贝娄是我到目前为止的代码
<script>
var getColor = prompt("Choose your color ", "Enter the color ");
var color;
var el = document.getElementById("color");
el.innerHTML = "Whatever paragraph message.";
if (getColor == "Yellow" || getColor == "yellow" || getColor == "YELLOW") {
color = "#FFFF66";
el.style.borderColor = color;
}
else if (getColor == "Orange" || getColor == "orange" || getColor == "ORANGE") {
color = "#FF9900";
el.style.borderColor = color;
}
else if (getColor == "Purple" || getColor == "purple" || getColor == "PURPLE") {
color = "#6600CC";
el.style.borderColor = color;
}
答案 0 :(得分:2)
我更正了您的代码段以使其正常工作。您只需要访问HTML元素的style.borderColor。
元素
希望这有帮助!
var getColor = prompt("Choose your color ", "Enter the color ");
var color;
var el = document.getElementById("color");
el.innerHTML = "Whatever paragraph message.";
if (getColor =="Yellow" || getColor =="yellow" || getColor =="YELLOW"){
color = "#FFFF66";
el.style.borderColor = color;
}
.borders{
background-color:#00ffff;
border-color:#000000;
border-width:2px;
border-style:solid;
}
<p id="color" class="borders"></p>