douzoudang1511 2018-07-03 13:43
浏览 361

使用jQuery选择表中的所有第二个单元格值

I am working on a requirement, where I need to push numbers in text boxes to an array. The text boxes are in the 2nd cell in the table row and 3rd cell is a date picker.

The code snippet below is giving me all text field values along with date values in array. I need only the values of the text fields to that array. Please help me with solution.

var NumbersArray = $('#myTable input[type=text]').map(function() {
  return this.value;
}).get();
console.log(NumbersArray);

This piece of code below is also not working:

var secondCellContents = [],

$('#myTable tbody tr').each(function() {
  var $secondCell = $(this).children('td').eq(1).text(),
    secondCellContent = $secondCell.text();

  secondCellContents.push(secondCellContent);
});
console.log(secondCellContents);
  • 写回答

2条回答 默认 最新

  • doubo1883 2018-07-03 13:49
    关注

    You can do the same thing for 2nd cell also like:

    var secondCellContents = $('#myTable tbody tr').map(function() {
        return $('td:eq(1)', this).val();
    }).get();
    
    console.log(secondCellContents); 
    

    Also, the .val() method is primarily used to get the values of form elements such as input, select and textarea and .text() is used to get the combined text contents of each element. The .text() method returns the value of text and CDATA nodes as well as element nodes.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分