2012-01-03 62 views
2

我想更改所有標題,通常這很容易(並且可能仍然是)。 對我來說,顏色將只取決於數據屬性的propeties,所以我必須先過濾它。這工作,但現在只有我不能在頭上設置CSS。 我得到這個錯誤用jquery更改標題外觀

script.js:175Uncaught SyntaxError: Unexpected string

上:

$("h1").css("border-bottom":"2px solid rgb(255, 0, 0)"); 

我想我已經與 「H1」 結合$(本),但我不知道怎麼辦。

function setSectionColors() { 
    // set headlines correct color 
    var blockIncrement = 1/rows; 

    for(var i = 0; i < rows; i++) { 
     var min = i*blockIncrement; 
     var max = (i+1)*blockIncrement; 
     // sloppy fix 
     if(min > 0) { 
      min += 0.00000001; 
     } 

     $(".headline").filter(function() { 
      return ((parseFloat($(this).attr("data-rating")) >= min) && (parseFloat($(this).attr("data-rating")) <= max)); 
     }).each(function() { 
      // getRowColor here instand of red 
      console.log($(this)); 
      $("h1").css("border-bottom":"2px solid rgb(255, 0, 0)"); 
     }); 

    } 
} 

這是來自console.log($(this))的輸出之一;

<div class="headline" data-rating="0.428688799039" onclick="javascript:showArticle(769);" style="display: none; "> 
         <h1>Worsteling GroenLinks doet Femke Halsema pijn</h1>      <p><p>Oud-partijleider van GroenLinks Femke Halsema ziet haar partij &#8220;worstelen&#8221;, wat haar &#8220;pijn&#8221; doet. De worsteling van de partij heeft volgens Halsema ten dele te maken met Jolande Sap, haar opvolgster.</p></p>      <hr/> 

回答

6

使用逗號:

$("h1").css("border-bottom","2px solid rgb(255, 0, 0)"); 

或者使用對象:

$("h1").css({"border-bottom":"2px solid rgb(255, 0, 0)"}); 
+0

@hunter哈哈的編輯表示感謝。愚蠢的我:-P – Neal 2012-01-03 17:21:40

1
//$("h1").css("border-bottom" , "2px solid rgb(255, 0, 0)"); 
           here! 
+0

謝謝,我之前使用過一個對象,但後來我只想改變一個元素,所以這就是爲什麼我要它們。 – clankill3r 2012-01-03 17:20:29