Javascript getElementsByClassName.value返回未定义的值
我有一个html表格Javascript getElementsByClassName.value返回未定义的值,javascript,html,Javascript,Html,我有一个html表格 <table class="blog_table blog_table_res" cellspacing="0"> <thead> <tr> <th class="product-name">Product</th> <th class="product-price">Price</th> <th class="product-quantity">Qu
<table class="blog_table blog_table_res" cellspacing="0">
<thead>
<tr>
<th class="product-name">Product</th>
<th class="product-price">Price</th>
<th class="product-quantity">Quantity</th>
<th class="product-subtotal">Total</th>
</tr>
</thead>
<tbody>
<tr class="cart_item">
<td class="product-name" data-title="Product">
<a href="https://whatever/">Mouse</a> </td>
<td class="product-price" data-title="Price">
<span class="woocommerce-Price-amount amount"><span
class="woocommerce-Price-currencySymbol">$</span>74.50</span> </td>
<td class="product-quantity" data-title="Quantity">
<div class="quantity">
<label class="screen-reader-text" for="quantity_5c80f7b813ae9">Quantity</label>
<input type="number" class="input-text qty text" step="1" min="0" max=""
/>
</div>
</td>
<td class="product-subtotal" data-title="Total">
<span class="woocommerce-Price-amount amount"><span
class="woocommerce-Price-currencySymbol">$</span>74.50</span> </td>
</tr>
<tr>
<td colspan="6" class="actions">
<button type="submit" class="button" name="update_cart" value="Update cart">Update cart</button>
</tr>
</tbody>
我也试过:
var elements = document.getElementsByClassName("product-name");
var value = elements[0].value;
alert(value); // 1
我还尝试使用以下方法迭代该表:
function checkForm() {
var table = document.getElementsByClassName("shop_table");
var arr = new Array();
for (var i = 0, row; row = table.rows[i]; i++) {
for (var j = 0, col; col = row.cells[j]; j++) {
arr.push(row.cells[j].firstChild.value);
}
}
alert(arr);
仍然无法读取未定义的属性“0”
我浏览了所有页面并尝试了许多其他解决方案,请问我哪里弄错了,我需要从表中提取条目表单控件有值,表单元格没有值 它们有
textContent
,innerHTML
和其他一些东西,但没有value
s
var elements=document.getElementsByClassName(“产品名称”);
var value=元素[0]。textContent;
console.log(值)代码>
产品
价格
量
全部的
$74.50
量
$74.50
更新购物车
我在您的产品名称、产品价格、产品数量
元素中看不到任何值
属性。
元素没有“值”属性……一个小提示:当您遇到一个以前从未使用过的新HTML元素时,请搜索它,至少阅读两次关于该元素的文章,然后写一个标签。
function checkForm() {
var table = document.getElementsByClassName("shop_table");
var arr = new Array();
for (var i = 0, row; row = table.rows[i]; i++) {
for (var j = 0, col; col = row.cells[j]; j++) {
arr.push(row.cells[j].firstChild.value);
}
}
alert(arr);