原生js模拟输入input内容,并触发搜索事件
实现:document.querySelector('input').dispatchEvent(new InputEvent("input")
let searchInput = $(".bi-component-datalist-packs .bi-input");
searchInput.click();
sleep(300);
searchInput.val("medical");
sleep(300);
inputEvent(searchInput);
function inputEvent(selector) {
$(selector)[0].dispatchEvent(new InputEvent("input"));
}
function sleep(mill = 1000) {
let end = new Date().getTime() + mill;
while (true) {
if (new Date().getTime() > end) {
break;
}
}
}