在输入框的Javascript模拟pressing进入 [英] Javascript simulate pressing enter in input box

查看:99
本文介绍了在输入框的Javascript模拟pressing进入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有什么似乎是一个简单的解决一个问题,但在尝试一吨不同的解决方案网上似乎没有任何工作对我后。

I have what seemed to be a simple fix to a problem but after trying a ton of different solutions online nothing seems to work for me.

我在每次输入或preSS在输入框中输入时间搜索数据表搜索栏,但后,我分配一个值到搜索框,当页面加载它不会做搜索,直到后用户无论是presses在框中输入或者类型/删除的信。我只是想找到一个解决方案来模拟按下回车键,但它似乎并没有工作。

I have search field that searches a data table every time you type or press enter in the input field, however after I assigned a value to the search box when the page is loaded it wont do the search until after the user either presses enter in the box or types / deletes a letter. I was just trying to find a solution to simulate hitting enter but it didn't seem to work.

下面是我的code:

<script type="text/javascript">
       window.onload = (function() {
           document.getElementById('search').value = " <?php echo $search;?>";

       });
</script>

这显然将值到什么我的PHP变量被设置为它工作正常的文本在页面加载中加载,它只是不执行搜索就像我说的,除非用户presses请在框中输入或删除/添加在输入框中的信。

This obviously assigns the value to what my php variable is set to which works fine the text is loaded in the box on page load, it just doesnt perform the search like I said unless the user presses enter in the box OR deletes/adds a letter in the input box.

搜索框code是

<input type="text" id="search" aria-controls="DataTables_Table_0" class="text">

更新:这是我的文件上发现正是我使用 http://datatables.net/ref

推荐答案

试试这个

document.getElementById("formId").submit();

这篇关于在输入框的Javascript模拟pressing进入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆