2015-03-22 2 views
0

Я хочу получить количество элементов из тега. Это мой исходный код:Ошибки при запуске Javascript-кода в Tomcat

<table class="tablehienthi" id="table"> 
<thead class="theadhienthi"> 
    <tr> 
    <th class="thhienthi">Niên Khóa</th> 
    <th class="thhienthi">Hệ Đào Tạo</th> 
    </tr> 
</thead> 
<tbody class="tbodyhienthi"> 
    <tr class="trhienthi"> 
    <td class="tdhienthi"><a style="text-decoration: none; color: rgb(30, 144, 255);" href="#">Niên Khóa 2010-2015</a></td><td class="tdhienthi">Cư Nhân</td> 
    </tr> 
    <tr class="trhienthi"> 
    <td class="tdhienthi"><a style="text-decoration: none; color: rgb(30, 144, 255);" href="#">Niên Khóa 2010-2015</a></td><td class="tdhienthi">Kỹ Sư</td> 
    </tr> 
    <tr class="trhienthi"> 
    <td class="tdhienthi"><a style="text-decoration: none; color: rgb(30, 144, 255);" href="#">Niên Khóa 2009-2014</a></td><td class="tdhienthi">Cư Nhân</td> 
    </tr> 
</tbody> 

Когда я запускаю код в браузере, если я не запустить его с TOMCAT затем код:

$(".tablehienthi tr").children().length return 8 

иначе, если я бегу с котом:

$(".tablehienthi tr").children().length return 0. 

Я не понимаю? Я хочу получить $(".tablehienthi tr").children().length, когда я буду работать с tomcat. Полный мой исходный код:

<body> 
    <table class="tablehienthi" id="table"> 
<thead class="theadhienthi"> 
    <tr> 
    <th class="thhienthi">Niên Khóa</th> 
    <th class="thhienthi">Hệ Đào Tạo</th> 
    </tr> 
</thead> 
<tbody class="tbodyhienthi"> 
    <tr class="trhienthi"> 
    <td class="tdhienthi"><a style="text-decoration: none; color: rgb(30, 144, 255);" href="#">Niên Khóa 2010-2015</a></td><td class="tdhienthi">Cư Nhân</td> 
    </tr> 
    <tr class="trhienthi"> 
    <td class="tdhienthi"><a style="text-decoration: none; color: rgb(30, 144, 255);" href="#">Niên Khóa 2010-2015</a></td><td class="tdhienthi">Kỹ Sư</td> 
    </tr> 
    <tr class="trhienthi"> 
    <td class="tdhienthi"><a style="text-decoration: none; color: rgb(30, 144, 255);" href="#">Niên Khóa 2009-2014</a></td><td class="tdhienthi">Cư Nhân</td> 
    </tr> 
</tbody> 
    </table> 
    <script src="js/jquery-1.9.1.js"></script> 
    <script langauage="javascript"> 
     $('document').ready(function(){ 
      var temp= $(".tablehienthi th").children().length; 
      alert(temp); 
     }); 
    </script> 
</body> 
+2

Что? Как вы ожидаете запустить операцию JQuery DOM в Tomcat? Как минимум, нам нужно гораздо больше кода и контекста. – chrylis

+0

@chrylis помогите мне! –

+0

Вы хотите подсчитать строки или данные таблицы? –

ответ

0

Для подсчета строк таблицы, попробуйте следующее:

<body> 
    <table class="tablehienthi" id="table"> 
<thead class="theadhienthi"> 
    <tr> 
    <th class="thhienthi">Niên Khóa</th> 
    <th class="thhienthi">Hệ Đào Tạo</th> 
    </tr> 
</thead> 
<tbody class="tbodyhienthi"> 
    <tr class="trhienthi"> 
    <td class="tdhienthi"><a style="text-decoration: none; color: rgb(30, 144, 255);" href="#">Niên Khóa 2010-2015</a></td><td class="tdhienthi">Cư Nhân</td> 
    </tr> 
    <tr class="trhienthi"> 
    <td class="tdhienthi"><a style="text-decoration: none; color: rgb(30, 144, 255);" href="#">Niên Khóa 2010-2015</a></td><td class="tdhienthi">Kỹ Sư</td> 
    </tr> 
    <tr class="trhienthi"> 
    <td class="tdhienthi"><a style="text-decoration: none; color: rgb(30, 144, 255);" href="#">Niên Khóa 2009-2014</a></td><td class="tdhienthi">Cư Nhân</td> 
    </tr> 
</tbody> 
    </table> 
    <script src="//code.jquery.com/jquery-1.11.2.min.js"></script> 
    <script langauage="javascript"> 
     $('document').ready(function(){ 
      var temp= $("tbody tr").length; 
      alert(temp); 
     }); 
    </script> 
</body> 

Для подсчета данных Таблица изменения JavaScript для этого:

<script langauage="javascript"> 
      $('document').ready(function(){ 
       var temp= $("tbody tr").children().length; 
       alert(temp); 
      }); 
     </script> 
+0

большое спасибо @Addel Ahmad –