jQuery选择输入[type=image]同级
我正在尝试将这些表单转换为ajax (举例) 我无法执行$(输入[name=“barcode”])之类的操作jQuery选择输入[type=image]同级,jquery,jquery-selectors,Jquery,Jquery Selectors,我正在尝试将这些表单转换为ajax (举例) 我无法执行$(输入[name=“barcode”])之类的操作 有什么想法吗?你需要做以下事情: $('input[type=image]').click(function(){ var image = $(this); var parent = image.parent(); // this will be the fieldset, could also do .closest('fieldset)', if the fields
有什么想法吗?你需要做以下事情:
$('input[type=image]').click(function(){
var image = $(this);
var parent = image.parent(); // this will be the fieldset, could also do .closest('fieldset)', if the fieldset is not the immediate parent
var neededInput = $('input[name=barcode]', parent);
// do something with it
return false;
});
或者使用-method
在单击功能中,
此
将是对您单击的图像的引用。所以你可以
$(this).siblings()
或
也许我误解了你的意思,但我只得到了其他输入的图像类型。。。
$('input[type=image]').click(function(){
var image = $(this);
var parent = image.parent(); // this will be the fieldset, could also do .closest('fieldset)', if the fieldset is not the immediate parent
var neededInput = $('input[name=barcode]', parent);
// do something with it
return false;
});
$('input[type=image]').click(function (event){
event.preventDefault();
var $image = $(this);
var $neededInput = $image.siblings('input[name=barcode]');
// do something with it
});
$(this).siblings()
$(this).closest('fieldset').find(...);