我正在尝试创建一个脚本,用户可以在其中更改文本框背景的颜色并添加边框,我有背景工作和边框脚本工作,但我似乎无法弄清楚如何添加边框可选,这是脚本:
function newColor(){
var colorChange = prompt('What color would you like the background?');
var borderConfirm = confirm('Would you like a border?');
var borderSize = prompt('Would you like your border to be thin, medium, or thick?');
var borderColor = prompt('What color would you like your border?');
if(borderConfirm == true){
borderSize;
borderColor;
}
else{
alert('No border will be added');
}
document.getElementById('backgroundcolorchange').style.backgroundColor = colorChange;
document.getElementById('backgroundcolorchange').style.borderWidth = borderSize;
document.getElementById('backgroundcolorchange').style.borderColor = borderColor;
console.log(borderSize);
console.log(borderColor);
}
#backgroundcolorchange{
background-color:#900;
width:auto;
height:auto;
position:absolute;
border:.001px #900 solid;
}
<div id="backgroundcolorchange" onClick="newColor()">
<p id="test" style="margin:0;"> Your Text Will Go Here! </p>
</div>
直到后来它才提供选项,我不知道我的变量或我的陈述是否有问题。请帮忙。
答案 0 :(得分:0)
function newColor(){
var colorChange = prompt('What color would you like the background?');
var borderConfirm = confirm('Would you like a border?');
if(borderConfirm == true){
var borderSize = prompt('Would you like your border to be thin, medium, or thick?');
var borderColor = prompt('What color would you like your border?');
}
答案 1 :(得分:0)
function newColor(){
var colorChange = prompt('What color would you like the background?');
var borderConfirm = confirm('Would you like a border?');
if(borderConfirm == true){
var borderSize = prompt('Would you like your border to be thin, medium, or thick?');
var borderColor = prompt('What color would you like your border?');
document.getElementById('backgroundcolorchange').style.borderWidth = borderSize;
document.getElementById('backgroundcolorchange').style.borderColor = borderColor;
}
else{
alert('No border will be added');
}
document.getElementById('backgroundcolorchange').style.backgroundColor = colorChange;
console.log(borderSize);
console.log(borderColor);
}
&#13;
#backgroundcolorchange{
background-color:#900;
width:auto;
height:auto;
position:absolute;
border:.001px #900 solid;
}
&#13;
<div id="backgroundcolorchange" onClick="newColor()">
<p id="test" style="margin:0;"> Your Text Will Go Here! </p>
</div>
&#13;