Jquery 如何从第一个输入标签的函数运行第二个输入标签的oninput函数

Jquery 如何从第一个输入标签的函数运行第二个输入标签的oninput函数,jquery,html,Jquery,Html,我想从第一个输入标签函数运行第二个输入标签的oninput函数。它与第二个输入标签函数的onchange函数一起工作。 有一个onchange函数的示例:- HTML 但问题是,当我更改$('#b').change()时到$('#b')。输入()它什么都不起作用 oninput示例如下:- JQuery这是一个什么都不起作用的问题 请告诉我这个问题的解决方案。jQuery中没有input()方法。控制台中的错误应说明:“输入不是函数”。使用时应使用trigger $('#a')。关于(“更改”

我想从第一个输入标签函数运行第二个输入标签的oninput函数。它与第二个输入标签函数的onchange函数一起工作。 有一个onchange函数的示例:-

HTML

但问题是,当我更改
$('#b').change()时
$('#b')。输入()它什么都不起作用

oninput示例如下:-

JQuery这是一个什么都不起作用的问题

请告诉我这个问题的解决方案。

jQuery中没有input()方法。控制台中的错误应说明:“输入不是函数”。使用时应使用
trigger

$('#a')。关于(“更改”,函数(){
$('#b')。触发器('input');
});
$('#b')。关于(“输入”,函数(){
警报($(this.index());
});


这是因为您必须触发“input”。与其使用
$('b').input()
试试使用
$('b')。触发器(“input”)

我个人会说提取方法,以避免将所有逻辑都通过DOM

function alertB () {
  alert($b.index());
}

var $b = $('#b').on("input", alertB);

$('#a').on("change", alertB);

您还可以使用来触发特定事件

$('#a').on("change",function() {
    $('#b').trigger("input");
});

$('#b').on("input",function() {
  alert($(this).index());
});
$('#a').on("change",function() {
    $('#b').input();
});

$('#b').on("input",function() {
  alert($(this).index());
});
function alertB () {
  alert($b.index());
}

var $b = $('#b').on("input", alertB);

$('#a').on("change", alertB);

$('#a').on("change",function() {
    $('#b').trigger("input");
});

$('#b').on("input",function() {
  alert($(this).index());
});