一、trigger()触发器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../js/jquery3.7.js"></script>
<script>
$(function(){
$('#mybtn').on('click',function(){
$('input[name=mytext]').val("nihao");
$('input[name=mytext]').trigger('input');
});
$('input[name=mytext]').on('input',function(){
alert($('input[name=mytext]').val());
})
// 自动触发事件(对于最外面的函数),必须写在前面已经定义的后面
$('input[name=mytext]').trigger('input');
})
</script>
</head>
<body>
<input type="button" value="按钮" id="mybtn">
<input type="text" name="mytext">
</body>
</html>