jQuery:访问数据表中的文本框的值 [英] jquery: access value of a textbox in datatable

查看:63
本文介绍了jQuery:访问数据表中的文本框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数据表中,我通过添加添加了文本框列(第二列):

In a datatable, I added a textbox column (2nd column) by append:

 var textbox= '<input type="text" class="txtBox">';

但是现在,我想获取文本框的值.我是通过以下方式做到的:

But now, I want to get the value of the textbox. I am doing this via:

 var row_index;

 $(document).on('mouseover', '#table1 tr', function() {
    row_index = this.rowIndex;
 });

  function getIncrement() {

    var dtable = $('#table1').DataTable();
    var textvalue = dtable.rows(row_index).cells(1).value; //textbox column is 2nd
    alert(parseFloat(textvalue));

  }

问题是我得到的是"NaN" (不是数字)值.如果删除parseFloat,我将得到未定义".有任何想法吗?预先谢谢你.

The problem is I am getting a 'NaN' (Not a number) value. If I remove parseFloat, I am getting 'undefined'. Any ideas? Thank you in advance.

P.S. row_index值就好了.如果我使用alert获取其值,则表示获取正确的索引.另外,使用索引获取其他行值的值也没有问题.我只有"txtbox"列有问题.谢谢

P.S. the row_index value in just fine. If I use alert to get its value, I am getting the correct index. Also, I have no problem getting the value of other row values using the index. I only have problem with the "txtbox" column. Thanks

推荐答案

您可以存储row而不是rowIndex,然后使用 val()以获得其值.

You can store row instead of rowIndex and later find the textbox within it using find(). Once you get the element call val() to get its value.

$(document).on('mouseover', '#table1 tr', function() {
    current_row = this;
});

function getIncrement() {
    alert(parseFloat( $(current_row).find(".txtBox").val()));
}

这篇关于jQuery:访问数据表中的文本框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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