첫째, jsfiddle ... 이제 http://jsfiddle.net/therocketforever/jYba3/11/jQuery로 배경색을 변경 한 후 재설정하는 방법은 무엇입니까?
// Highlight selected linker link & set all others to default.
$('a.linker').click(function(){
$(this).addClass('selected');
$(this).parent('li').siblings().find('.selected').removeClass('selected');
// Selects a random colour from the 'colors' array by getting a random value
// between 0 and the length of the color array.
rand = Math.floor(Math.random()*colors.length);
$(this).css("background-color", colors[rand]);
질문하기,
는 첫째로이 코드는 거의 정확하게 내가 사용자는 링크, 선택한 색상을 클릭, 그것을 원하는 방식으로 작동 링크 텍스트에 적용되고 다른 링크는 제거됨 & 링크 배경이 색상 배열에서 임의의 색상으로 설정됩니다. 시원한.
내가 알고 싶은 것은 ... 무작위로 설정된 배경색이 선택되지 않은 링크 (예 : .selected 클래스의 링크에만 배경색이 있습니다.)에서 제거되도록하려면 어떻게해야합니까?
같은 배경 색상이 두 번 연속 사용되지 않습니다
Bonas 포인트 경우 EXTRA CREDIT. .. (즉, 노란색 하나 개의 세트를 클릭하여 두 개의 노란색 제외한 다른 색상을 클릭하면
@pimvdb :'.siblings()'는'this'를 포함하지 않을 것입니다. 그래서 우리는'selected' 클래스를 갖는'this'로 끝날 것이고, 다른 링크 ('li a')는 그렇지 않을 것입니다. –
방금 알아 챘습니다. 미안 해요. 신경 쓰지 마. – pimvdb