我在写通讯录,但遇到了问题。
代码:
<label for="file">A picture </label><br>
<label for="file">Another picture </label>
<input type="file" id="file" class="1"/>
<input type="file" id="file" class="2"/>
$('input:file').change(function(){
alert(this.className)
})
我的问题:我无法从每个元素中获取类名称。单击第二个元素时,将显示第一个元素的类名。
HTML元素的ID应该是唯一的(http://www.w3schools.com/tags/att_global_id.asp)。 因此,jQuery无法区分两个都具有ID“文件”的元素。
编辑:
实际上我的第一个答案是错误的,jQuery可以区分,但是两个标签都分配给了第一个元素。更新的小提琴
<label for="file1">A picture </label><br>
<label for="file2">Another picture </label>
<input type="file" id="file1" class="1"/>
<input type="file" id="file2" class="2"/>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句