Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从下面的屏幕截图中选择td值的javascript代码_Javascript_Html_Jquery_Html Table_Element - Fatal编程技术网

从下面的屏幕截图中选择td值的javascript代码

从下面的屏幕截图中选择td值的javascript代码,javascript,html,jquery,html-table,element,Javascript,Html,Jquery,Html Table,Element,从下面的屏幕截图中,有两个问题是作为javascript开发人员的新手提出的。 我想直接从javascript代码中的$'cart-subtotal-order.total.subtotal td'中获取第二个td的值。这是第一个问题。第二个问题是如何获得$'.amount grand total'的值。使用val来表示$'.amount grand total'.val这样的值是正确的吗?还是应该使用text来表示该值的常规文本值 如果您想从tr获得第二个td: 那么,如果您想获得总计,则如下

从下面的屏幕截图中,有两个问题是作为javascript开发人员的新手提出的。 我想直接从javascript代码中的$'cart-subtotal-order.total.subtotal td'中获取第二个td的值。这是第一个问题。第二个问题是如何获得$'.amount grand total'的值。使用val来表示$'.amount grand total'.val这样的值是正确的吗?还是应该使用text来表示该值的常规文本值

如果您想从tr获得第二个td:

那么,如果您想获得总计,则如下所示:

要获取第二行文本,可以使用以下代码

为了得到总数


请不要将代码作为图像发布。通常我们想看看你是如何解决这个问题的,而不是仅仅问一个问题;-。val获取/设置输入元素的值,.text获取/设置HTML元素的文本,因此在您的示例中没有输入元素,因此使用.text
var subtotal = $('#cart-subtotal-order.total.subtotal').find("td:eq(1)").text();
var grand_total = $('#totalRow .grand-total').text();
var seondRow =  $("table>#cart-subtotal-order.total.subtotal> td:nth-child(2)").text(); 
var grandTotal = $('#totalRow .grand-total').text(); 
var grandTotal = $('#totalRow .grand-total').value();