从javascript发送回车

Send enter from javascript

本文关键字:回车 javascript      更新时间:2024-05-12

如何将输入从javascript发送到站点

我真正需要的是在搜索框中将文本发送到filehippo.com这样的网站,然后按enter键搜索这些文本
所以来自站点的代码是:

<div id="searchbox">
<form name="f" action="/search">
<input style="color: #999" type="text" id="q" name="q" maxlength="150" value="Search..." onfocus="javascript:clearInputValue('q', 'Search...')" onblur="javascript:setDefaultIfEmpty('q', 'Search...')">
<input type="submit" id="search-submit" value="GO" onclick="javascript:submitQuery('q', 'Search...')">
</form></div>

我的简单代码如下:

javascript: document.getElementById('q').focus();document.getElementById('q').value='Winrar';document.getElementById('f').item(0).click();

这些脚本只是把重点放在搜索框上并向他们发送文本,但我还需要自动搜索(发送输入),如何做到这一点?

document.getElementById('f').item(0).click(); -> dont work

我需要的是通过输入模拟鼠标点击,因为无法将点击发送到正常工作的元素。

可以用文本发送输入吗?

使用document.f.submit();提交表单。

问题是有多种形式被命名为"f"

javascript:document.f[0].submit();

因此,完整的功能线将是:

javascript:document.getElementById('q').value='Winrar';document.f[0].submit();

使用输入元素的onkeypress属性。