你的html有一些问题,而你的jQuery一开始就像SKS所说的那样,你的html文档中不能有多个具有相同ID的节点. ID必须是唯一的.我推荐使用一个类.
您还应该在< thead>中添加标题行和< tbody>中的表格正文
现在,在您的jQuery上,$(“td”)将找到文档中的所有td,而不仅仅是行中的td.
你会想要使用
$(this).find(‘td’)或者您可以使用.children或更高级别的选择器.有许多不同的,正确的方法来获取此信息.
我已经采用你的代码并修改它:
$("tbody").find("tr").each(function() { //get all rows in table
var ratingTdText = $(this).find('td.Rating').text();
//gets the text out of the rating td for this row
alert(ratingTdText);
这适用于稍微修改的html:
CoffeeID Degree Weight Profile UsageInfo Comments AmbientTemp Rating WeightDeducted Selected ProfileID ProfileStart
1 1 3 9 Filter Brew Perfecto!! 55 4.25 1 4 34 1 3 15 99 87 Espresso WTF 99 4.5 5 3 66 4
希望这有助于您朝着正确的方向前进!
哦,我差点忘了!这里是一个jsfiddle的链接,所以你可以看到这个在行动:http://jsfiddle.net/fCpc6/
本篇重点是在学:1、
jquery
选择器 2、
jquery
find()3、
jquery
each()
内容
描述:给一张
表
格,用来颜色来显示事务的不同状态,红色代
表
有人,蓝色代
表
空闲,黄色代
表
繁忙,怎样用
jquery
来实现这样的效果?html部分:<table>
<tr>
<
td
>1</
td
>
<
td
>...
html-使用包含
td
包含其他元素的
jQuery
替换
td
内的
文本
我的
表
如下:8: Tap on APN and Enter www.我只想
更改
文本
8: Tap on APN and Enter www.不影响隐藏的领域我正在尝试使用
jQuery
,但未找到解决方案function changeText() {$("#demoTable
td
").each(function () {for (var ...
$('.btn-primary').click(function(){ var tr=$(this).closest("tr"); var coll_data1=tr.find("
td
:eq(0)").text(); var coll_data2=tr.find("
td
:eq(1)").text();)};
1.页面引入
jquery
,使用就绪函数,这样页面加载就可以调用函数进行
表
格数值
更改
:
$(document).ready(function(){
changeTotalSpace();
changUs
在for循环tr内获取值:
var first
Td
Text = tr[i].find('
td
').eq(0).text();
这种方法会报错,tr[i].find is not a function。是因为tr[i]得到的是原生的tr解构,因为原生js没有find()方法,所以会报错:
console.log(tr[i]);
解决方法一:
var first
Td
Text = $(tr
$(document).ready(function () {$("#selEmployee").click(function () {var $table = $("#tbProEmployee tr");var len = $table.length;var trid = "tbProEmployee" + len;var strDeviceTr = "";strDeviceTr += "";...