[英]How to get input value with no id using JavaScript?
I have an editable DataTabe and when edit mode, the generated html is exactly as shown below: 我有一个可编辑的DataTabe,在编辑模式下,生成的html如下所示:
<td><form><input autocomplete="off" name="value" ></form></td>
There is s TextBox as input and I need t get the value of this input. 有一个TextBox作为输入,我不需要获取此输入的值。 However, I cannot give id as there is no configuration of DataTable and I decided to get the value using Javaascipt.
但是,我无法提供id,因为没有DataTable的配置,因此我决定使用Javaascipt获取该值。 I have tried many different methods like closest() as shown below, but cannot get the value.
我已经尝试了很多不同的方法,例如mostest() ,如下所示,但无法获取该值。 Is it possible to grab it?
有可能抓住它吗?
var $row = $(this).closest("tr");
$tds = $row.find("td");
You might use document.querySelector
: 您可以使用
document.querySelector
:
var input = document.querySelector('[name="value"]`);
Or, using jQuery, you could also use the same selector: 或者,使用jQuery,您还可以使用相同的选择器:
var input = $('[name="value"]');
您的问题很难理解,可以直接使用jQuery定位name属性(我看到您使用的是jQuery,而不是JavaScript),并使用.val()来获取输入值,如下所示:
$("input[name='value']").val();
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
});
then you can get currentInput.value()
那么你可以得到
currentInput.value()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.