Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何在没有提交按钮的情况下提交字段中的文本_Jquery_Forms_Tampermonkey - Fatal编程技术网

Jquery 如何在没有提交按钮的情况下提交字段中的文本

Jquery 如何在没有提交按钮的情况下提交字段中的文本,jquery,forms,tampermonkey,Jquery,Forms,Tampermonkey,我现在搜索和尝试了几个小时,我能找到的就是如何提交一个有提交按钮的文本,但我需要提交一个没有提交按钮的文本字段,我不能发布页面链接,因为它需要登录。但以下是文本字段的代码: <div class="items box module"> <div class="title"> <input type="text" id="filter" placeholder="Type an item

我现在搜索和尝试了几个小时,我能找到的就是如何提交一个有提交按钮的文本,但我需要提交一个没有提交按钮的文本字段,我不能发布页面链接,因为它需要登录。但以下是文本字段的代码:

    <div class="items box module">
                <div class="title">
                    <input type="text" id="filter" placeholder="Type an item name or type and press enter!" />
我需要一种方法来选择该字段,就像我点击它并按enter键发送它一样。或使用已尝试过的代码执行此操作的其他方法。单击;选择并发送。提交以发送,但它不起作用

我刚接触tampermonkey和java,如果我遗漏了一些明显的问题或问了一些愚蠢的问题,我很抱歉

欢迎提供任何帮助,非常感谢

您需要类似以下内容:document.getElementByIdMyForm.submit


其中MyForm是实际文本字段所在表单的id。

只需将输入包装在表单中,然后当您键入并点击enter时,它将自动提交,这就是您要做的吗

请在此处查看它的实际操作:

如果在文本输入中单击时需要函数,请使用:

function focus() {
 //
}
document.getElementById('filter').addEventListener("onfocus", focus);

现在重读我的问题,我想我忘记了一些细节,这个页面就像一个包含多个项目的大列表,您在这个过滤器中键入并按enter键,列表将更改为包含您键入的内容的结果,而无需刷新或转到其他页面感谢您的回复,我正在尝试以某种方式自动键入并按enter键,不必按ENTER键,我看,ok,然后尝试类似的操作,如果您需要一个提交函数进行验证,等等,请按照该侦听器的上一个示例进行操作:
 <div class="items box module">
                <div class="title">
                    <form id="filterForm">
                    <input type="text" id="filter" placeholder="Type an item name or type and press enter!" />
                    </form>
function submitForm() {
   console.log('form submit');
    return false;
};

document.getElementById('filterForm').addEventListener("submit", submitForm);
function focus() {
 //
}
document.getElementById('filter').addEventListener("onfocus", focus);