[英]JQuery get value of elements selected by Attribute-Starts-With-Selector
我正在尝试获取正则表达式选择的每个元素的每个值。
具体来说,我有一个这样的输入列表,由循环生成
<input type="file" name="file[{$some_file.id}]">
我正在尝试通过jquery来获取每个输入的值
$("input[name^='file[']").change(function () {
//get each input value
})
我尝试了this.val()
但显然没有用。 非常感谢您的帮助。
this
绑定的事件处理程序是元素本身,而不是jQuery
对象。
来自.on()
当jQuery调用处理程序时,
this
关键字是对传递事件的元素的引用
所以你要
this.value
参见https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/input/file#Value
$('input[name^="file["]').on('change', function() { console.info(this.name, this.value) })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="file" name="file[0]"> <input type="file" name="file[1]"> <input type="file" name="file[2]"> <input type="file" name="not-this-one">
或者,将元素包装在这样的jQuery
对象中,并使用.val()
方法
$(this).val()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.