更改边框颜色Javascript

时间:2016-10-23 03:50:38

标签: javascript

你好我是非常新的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;
    }

1 个答案:

答案 0 :(得分:2)

我更正了您的代码段以使其正常工作。您只需要访问HTML元素的style.borderColor。

    我改变了什么:
  • #borders用于id =“borders”,所以我改为.borders并将CSS类边框添加到

    元素

  • 'solid'值适用于border-style属性
  • 您的'promptUser'变量不存在,所以我用静态文本
  • 更改了它

希望这有帮助!

 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>