我想使用 jquery 以编程方式输入单词或短语,然后从我的控制台触发 Google 搜索框自动完成建议。
这是我到目前为止所尝试的:
// Inject JQuery into page from console
var script = document.createElement("script");
script.src = "https://code.jquery.com/jquery-2.1.4.min.js";
document.body.appendChild(script);
// Add the word DOG into the search box
//** This part works **
$('input[name="q"]').val("dog");
// Attempt #1 to simulate clicking on the box
// ** This did appear to add a focus look to the box but it did not trigger the autocomplete suggestions listing
$('input[name="q"]').trigger("click");
// Attempt #2 to simulate clicking on the box
// ** This did not work.
$('input[name="q"]').trigger("mouseup");
如果我以编程方式完成注入 jquery 的第一部分,然后输入单词 dog,它就可以完美地工作。我什至可以手动点击搜索框,即使我没有手动输入,我也会看到所有关于 dog 的搜索建议。问题是我似乎无法通过 jquery 弄清楚如何以编程方式模拟导致它在我手动单击时显示自动建议的正确事件。