简体   繁体   English

Javascript 单击输入字段并输入

[英]Javascript click an input field and enter

Is it possible in javascript or Jquery to click on an input field in my case:在我的情况下,是否可以在 javascript 或 Jquery 中单击输入字段:

<input id="search" type="text" placeholder="...">

and push Enter然后按 Enter

I think you want to submit the form when the input is clicked so:我认为您想在单击输入时提交表单,因此:

var input = document.querySelector('input'),
    form = document.querySelector('form');

input.addEventListener('click', function(){
    form.submit();
});

In terms of a form you can use JQuery post and get methods Example.就表单而言,您可以使用 JQuery post 和 get 方法示例。 $(#id).click(function (){ $.post("url", {variable}); }); $(#id).click(function (){ $.post("url", {variable}); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM