我有一些带有输入的div。现在我想在每次输入发生变化时发起事件。到目前为止一切都很好:)但如果我选择第一个输入的文件,我不希望事件发生。
这是源
HTML:
<div class="someForm">
<input type="file" name="logo" class="logoselector" />
<br />
<div class="row-fluid">
<input type="text" name="firmenname" />
<br />
<input type="text" name="adresse" />
<br />
<input type="text" name="telefon" />
<br />
<input type="text" name="fax" />
</div>
</div>
这是jquery
$('.someForm').on('change', function(){
alert('changed');
});
我已经尝试了一些结构:not(...)但没有结果:/
答案 0 :(得分:1)
$('.someForm input:not(:first)').on('change', function(){
alert('changed');
});
这样jQuery将查找所有输入,但不会查找第一个::not(:first)
您还可以使用:file
中的:not()来定位file
类型
像:
$('.someForm input:not(:file)').on('change', function() {
alert('changed');
});
答案 1 :(得分:1)
答案 2 :(得分:1)
您可以在.on()
中添加选择器作为第二个参数,以排除type='file'
的输入:
$('.someForm').on('change', ':input[type!="file"]', function() {
alert('changed');
});
答案 3 :(得分:0)
您可以像这样更改选择器:
$('.someForm :not(:file)').on('change', function() {
alert('changed');
});
<强> Demon 强>
答案 4 :(得分:0)
您可以使用e.target.className
:
$('.someForm').on('change', function(e){
if (e.target.className != 'logoselector') {
alert('changed');
}
});