边框左边的颜色在javascript中不起作用

时间:2014-02-14 10:47:07

标签: javascript jquery html css

我尝试使用此脚本更改border-left-color,但我不断获得Uncaught SyntaxError: Unexpected token -

是否支持border-left-color?

的Javascript

function logoChange() { 
var description = new Array ();
description[0] = "images/logo/blue.png";
description[1] = "images/logo/green.png";
description[2] = "images/logo/orange.png";
description[3] = "images/logo/purple.png";
description[4] = "images/logo/red.png";
description[5] = "images/logo/yellow.png";
var size = description.length;
var x = Math.floor(size*Math.random());
document.getElementById('logo').src=description[x];

var colors = ['#20A3DC', '#72BF48', '#F58623', '#AF3292', '#EA352E', '#FED608'];

var thecolor = colors[x];

$('li span').css({color: thecolor});


$(".orbit-container .orbit-next span").hover(function () {
    $(this).css({
        border-left-color: thecolor  //border-left-color
    });
}, function () {
    $(this).css({
        border-left-color: 'black'  //border-left-color
    });
});


$("a").hover(function () {
    $(this).css({
        color: thecolor
    });
}, function () {
    $(this).css({
        color: 'black'
    });
});

}

window.onload=logoChange;

错误消息

enter image description here

6 个答案:

答案 0 :(得分:4)

你应该在css属性和静态值周围使用引号,而assigning.it应该是:

$(this).css({
    'border-left-color': thecolor  //border-left-color
});

答案 1 :(得分:2)

您有几种选择:

添加引号:

$(this).css({
    'border-left-color': thecolor
});

“snakename”属性:

$(this).css({
    borderLeftColor: thecolor
});

或者甚至,因为您只有一个要更改的属性,请简化:

$(this).css('border-left-color', thecolor);

答案 2 :(得分:0)

您必须将其括在字符串文字中:

... $(this).css({
     'border-left-color':  theColor
    });
..

答案 3 :(得分:0)

试试这个:

$("selector").css('border-left', 'solid 1px red');

演示:http://jsfiddle.net/9Q9Vm/1/

答案 4 :(得分:0)

您可以选择两个选项。

行情:

$(this).css({
    'border-left-color': '#AAA'
});

驼峰:

$(this).css({
    borderLeftColor: '#AAA'
});

答案 5 :(得分:0)

当你使用jquery设置CSS属性时,你总是需要使用camelcasing。因此,border-bottom变为borderBottomborder-left-color变为borderLeftColor

相关问题