有CSS代碼 定義了一些一個叫data-classbreak的屬性,取不同屬性值時的style效果:
path[data-classbreak="classbreak0"] {
stroke: rgb(255, 245, 220);
stroke-width: 1pt;
stroke-opacity: 0.35;
fill: #00008B;
fill-opacity: 0.8;
}
path[data-classbreak="classbreak1"] {
stroke: rgb(255 ,140 ,0);
stroke-width: 1pt;
stroke-opacity: 0.35;
fill: #1E90FF;
fill-opacity: 0.8;
}
path[data-classbreak="classbreak2"] {
stroke: rgb(255, 245, 220);
stroke-width: 1pt;
stroke-opacity: 0.35;
fill: #00008B;
fill-opacity: 0.8;
}
源代碼中有一句, node.setAttribute("data-classbreak", “classbreak0”);
即為一個節點的data-classbreak賦予classbreak0對應的style。
現在我需要用jquey動態地修改例如path[data-classbreak="classbreak0"]中的fill屬性,嘗試 $("path[data-classbreak='classbreak0]").css("fill","#33FF00")並沒有效果,請問應該怎麼改?謝謝!
$(".path[data-classbreak='classbreak0]").css("fill","#33FF00"); //注意前面的“.”,表示樣式,而單純的path的話就表示path元素,而你的node裡面並沒有path這樣的元素,肯定找不到的。汗!!!