[英]How get Data from a textbox and add it to dataTable?
I am trying to be able to get the information from the text ex:"Name,Number,etc";我试图能够从文本中获取信息,例如:“姓名、号码等”; and add that information to my data Table, but I cannot figure out how to get that part working.并将该信息添加到我的数据表中,但我不知道如何让该部分工作。 I also have the jsfiddle attached which works properly.我还附上了 jsfiddle,它可以正常工作。 ( https://jsfiddle.net/gon3j0uv/ ) ( https://jsfiddle.net/gon3j0uv/ )
$(document).ready(function() {
var t = $('#example').DataTable();
var counter = 1;
$('#addRow').on('click', function() {
t.row.add([
counter + '.1',
counter + '.2',
counter + '.3',
counter + '.4',
counter + '.5'
]).draw(false);
counter++;
});
// Automatically add a first row of data
$('#addRow').click();
});
<script src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
<link href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<button id="addRow">
addrow
</button>
</br>
</br>
</br>
First name:
<input type="text" name="FirstName">
<br>
</br>
</br>
</br>
</br>
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
<th>Column 5</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
<th>Column 5</th>
</tr>
</tfoot>
</table>
counter++;
} );
// Automatically add a first row of data
$('#addRow').click();
} ); });
You have to get the value in the input text, I edited your fiddle here is the link Example Fiddle您必须获取输入文本中的值,我在这里编辑了您的小提琴,链接示例小提琴
You have to get the value of the input like this:您必须像这样获取输入的值:
var inputText = $("input[name='FirstName']").val()
If you want text for all columns, you should have diferent input for each column.如果您想要所有列的文本,您应该为每一列提供不同的输入。 I hope it helps我希望它有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.