2014-02-28 32 views
0

我显示一个图表,但我必须在JavaScript代码中指定我的第th列(范围=行)。scope =行在JavaScript代码中未被识别(jquery.visualize插件)

在这种方式中使用的图表,HTML代码(例如,使用的):

<html> 
<head> 
    <script language="javascript" type="text/javascript" src="jquery-1.10.2.min.js"></script> 
    <script language="javascript" type="text/javascript" src="jquery.visualize.plugin.js"></script> 
    <link type="text/css" rel="stylesheet" href="base.css"/> 
    <link type="text/css" rel="stylesheet" href="jquery.visualize.plugin.css"/> 

    <script type="text/javascript"> 
     $(function(){ 
      $('table').visualize({type: 'line'}).appendTo('body'); 
     }); 
    </script> 
</head> 
<body> 
    <table> 
     <caption>2009 Employee Sales by Department</caption> 
     <thead> 
      <tr> 
       <td></td> 
       <th scope="col">2010</th> 
       <th scope="col">2011</th> 
       <th scope="col">2012</th> 
       <th scope="col">2013</th> 
       <th scope="col">2014</th> 
      </tr> 
     </thead> 
     <tbody> 
      <tr> 
       <th scope="row">Gastro</th> 
       <td>10</td> 
       <td>20</td> 
       <td>30</td> 
       <td>40</td> 
       <td>50</td> 
      </tr> 
      <tr> 
       <th scope="row">Pneumo</th> 
       <td>20</td> 
       <td>30</td> 
       <td>20</td> 
       <td>40</td> 
       <td>40</td> 
      </tr> 
      <tr> 
       <th scope="row">Procto</th> 
       <td>80</td> 
       <td>90</td> 
       <td>60</td> 
       <td>100</td> 
       <td>90</td> 
      </tr> 
     </tbody> 
    </table> 
</body> 
</html> 

可以看到,在TBODY,对于标记,我们使用范围= “行”

我使用datattable来填充表,我想知道如何在JavaScript代码中指定它。

我的javascript代码:

function fillDataTable(data) { 

if ($("#table_campaigns").css("visibility") == "hidden") 
    $("#table_campaigns").css("visibility", "visible"); 

$('#table_campaigns').dataTable({ 

    'aaData': data, 
    'aoColumns': [ 
     { "sTitle": "", "sCellType": "th", "fnCreatedCell": function (cell) { cell.scope = 'row';}}, 
     { "sTitle": "2010" }, 
     { "sTitle": "2011" }, 
     { "sTitle": "2012" }, 
     { "sTitle": "2013" }, 
     { "sTitle": "2014" } 
    ], 

    "iDisplayLength": 10, 
    "bJQueryUI": true, 
    "bDestroy": true, 
    "bPaginate": true, 
    "bLengthChange": false, 
    "bFilter": true, 
    "bSort": false, 
    "bInfo": false, 
    "bAutoWidth": false 
}); 
} 

我测试过$(TBODY>日).attr( '范围', '行')但不成功。

这里是我的图表:

enter image description here

回答

0

这样的工作对我来说:

$('table tbody th').attr('scope','row'); 

你只想寻找直接儿童时使用>th不是tbody的直接子女。 另外,您需要添加引号。

Live example

+0

我灌我的dataTable后添加和我有一样的图表。 我不明白为什么它不起作用。 – Jayce

+0

@Jayce您可以在我的示例中看到使用DOM检查器,我提供的代码正常工作。那么你可能还有其他问题。我的代码按照您的要求在'th'上添加了'scope ='row'''属性。 – Alvaro

+0

你应该接受这个答案,并提出另一个问题,因为这个问题已经解决了。 – Alvaro