在Tomcat中运行Javascript代码时出错
Errors when running Javascript code in Tomcat
我想要得到th标记的元素数量。这是我的源代码:
<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
否则,如果我使用tomcat运行:
$(".tablehienthi tr").children().length return 0.
我不明白?当我和tomcat一起跑步时,我想得到$(".tablehienthi tr").children().length
。完整的我的源代码:
<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>
要计数表行,请尝试以下操作:
<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>
相关文章:
- 我在代码点火器中出错
- 将javascript代码转换为jquery代码时出错
- 我的Javascript代码出错
- 在Tomcat中运行Javascript代码时出错
- 不允许的关键字符.通过 Codeigniter 中的 jQuery 在帧中加载嵌入代码时出错
- 运行Javascript继承代码时出错
- 将js代码转换为jQueryMobile时出错
- 将Flask中的变量显示为javascript代码时出错
- 代码在shell中运行,但提供'可以't查找变量'从文件运行时出错
- 我的代码出错
- 如何将鼠标悬停在链接上时显示demo_test.txt的内容?我哪里出错了,我的代码应该是什么样子
- 使用 qunit 测试我的代码时出错
- 使用 Lodash 合并数组,为什么结果是重复的数组值?,我的代码在哪里出错
- 语法加载具有现代化 JavaScript 代码的 html 页面时出错
- 从 JavaScript 函数调用 C# 方法背后的代码时出错
- Ajax 客户端框架运行 HTML 代码时出错
- 为什么这个依赖于HTML5地理位置的javascript代码出错
- Javascript:“;无法读取属性“”;name”;未定义的“;本地javascript代码出错
- Javascript和编程新手.我的代码出错了
- 使用javascript的代码出错