Jquery 使用自定义按钮输入的数字增量值

Jquery 使用自定义按钮输入的数字增量值,jquery,function,Jquery,Function,wordpress插件设置了一个数字字段,我无法在数字字段前后添加额外的HTML。我已经添加了一些CSS来删除默认箭头 因此,我在输入之前和之后使用jQuery添加了两个元素: $('.enviso-group-form .quantity input').each(function(i, obj) { $(this).before('<span class="selectNumber__increase selectNumber__change">+&l

wordpress插件设置了一个数字字段,我无法在数字字段前后添加额外的HTML。我已经添加了一些CSS来删除默认箭头

因此,我在输入之前和之后使用jQuery添加了两个元素:

$('.enviso-group-form .quantity input').each(function(i, obj) {
    $(this).before('<span class="selectNumber__increase selectNumber__change">+</span>');
    $(this).after('<span class="selectNumber__decrease selectNumber__change">-</span>');

    $(this).val(0);
});
不幸的是,这不起作用。它触发console.log,但我得到NaN,输入值保持为0。

.find('input')
将查找子代

获取当前匹配元素集中每个元素的后代

您可以使用
next
prev
作为另一个按钮)或
同级
,两者都将返回正确的结果

$oldValue = $(this).next('input').val();

$('.enviso group form.quantity input')。每个(函数(i,obj){
$(this.before('+');
$(此)。在('-')之后;
$(此).val(0);
});
$('.enviso group form.selectNumber\uu increase')。在('单击')上,函数(e){
$oldValue=$(this.next('input').val();
$newValue=parseInt($oldValue)+1;
log(parseInt($newValue));
$(this).next('input').val($newValue);
});

.find('input')
将查找后代

获取当前匹配元素集中每个元素的后代

您可以使用
next
prev
作为另一个按钮)或
同级
,两者都将返回正确的结果

$oldValue = $(this).next('input').val();

$('.enviso group form.quantity input')。每个(函数(i,obj){
$(this.before('+');
$(此)。在('-')之后;
$(此).val(0);
});
$('.enviso group form.selectNumber\uu increase')。在('单击')上,函数(e){
$oldValue=$(this.next('input').val();
$newValue=parseInt($oldValue)+1;
log(parseInt($newValue));
$(this).next('input').val($newValue);
});

$oldValue = $(this).siblings('input').val();