2016-11-13 52 views
0

我有一个可编辑的DataTabe当编辑模式,生成的HTML正是如下图所示:如何使用JavaScript获取没有id的输入值?

<td><form><input autocomplete="off" name="value" ></form></td> 

有是S文本框输入,我需要吨得到此输入的值。然而,我不能给id,因为没有DataTable的配置,我决定使用Javaascipt来获取值。我尝试了许多不同的方法,如最接近()如下所示,但无法获得该值。有可能抓住它吗?

var $row = $(this).closest("tr"); 
$tds = $row.find("td"); 

回答

3

您可以使用document.querySelector

var input = document.querySelector('[name="value"]`); 

或者,使用jQuery,你也可以使用相同的选择:

var input = $('[name="value"]'); 
+0

你摇滚!..非常感谢:) – hexadecimal

+0

@hexadecimal不客气! ;) –

1

你提的问题是很难理解,你可以针对name属性直接使用jQuery(我看你使用的是jQuery,而不是JavaScript),并获得输入值的使用.val(),如下所示:

$("input[name='value']").val(); 
+0

非常感谢您的回答。投票+ – hexadecimal

0
var currentInput=null; 

$("input").focus(function(e) 
{ 
    currentInput=e.target or this;//here you can get currently editing textfeild or may be $(this) if this is wrong 
}); 

那么你可以得到currentInput.value()

相关问题