动态生成的html表无法获取选定的td值 [英] dynamically generted html table cannot get selected td value

查看:79
本文介绍了动态生成的html表无法获取选定的td值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过许多 Google和stackoverflow示例

I have looked at MANY google and stackoverflow examples

我确实创建了一个小提琴来演示我的问题.

I did create a fiddle to demonstrate my problem.

问题陈述. 我想在点击人名时在第一列中获得该人的名字." 我这样做了,所以我们将鼠标悬停在每行突出显示为黄色的班级上,并且我可以让Jquery执行一个单击事件,这样就可以了,但是当我执行此代码时,它将为该列中的每一行吐出所有文本值

Problem statement. "I want to get the name of the person in the first column upon clicking on their name." I have it so on rollover the class for each row highlights in yellow and I CAN get Jquery to do a click event and so that works, but when I do this code it spits out all of the text values for every row in that column

 $(document).on('click', '.nameField', function () {
        //console.log('t');
        var x = $(".nameField").text();

        //var x = $(this).parent(".nameField").text();
        console.log(x);

    });

http://jsfiddle.net/bthorn/7ck1m7q1/2/

更多信息.

点击使用动态表格填充DIV"按钮

Click on the button "Fill DIV with Dynamic Table"

还在顶部,请注意一个STATIC,顶部的顶部可以正常工作,尽管名称只有问题

Also at the top , notice a STATIC one that on there at the top works to get the name no problem, well there is only one row though

更新该行需要别名,我在别名列的td上创建了一个新类,该如何获取?

http://jsfiddle.net/bthorn/7ck1m7q1/2/

推荐答案

您可以尝试

var x = $(this).text();

并获取别名:

var x = $(this).siblings('.alias').text();

这篇关于动态生成的html表无法获取选定的td值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆