使用jQuery事件keydown模拟在textarea上输入不起作用 [英] Simulate enter on textarea with jquery event keydown not working

查看:64
本文介绍了使用jQuery事件keydown模拟在textarea上输入不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使Facebook自动回复味精脚本,这是我的代码

I was trying to make facebook autoreply msg script, here is my code

$(window).load(function(){
var a=setInterval(function(){
var e = $('.titlebarText').html();
if(!e)
{
}
else
{
$('textarea.uiTextareaAutogrow.input').focus().val('Test!');
var c = jQuery.Event("keydown");
c.which = 13; 
$('textarea.uiTextareaAutogrow.input').trigger(c);
}
}
,5000);
});


$(window).load(function(){
var q=setInterval(function(){
$('.close').click()}
,6000);
});

一切正常,但是在专注于textarea并插入值之后模拟了enter.

Everything is working perfectly but simulating enter after focusing on textarea and inserting value..

推荐答案

您的选择器看起来很奇怪. textarea.uiTextareaAutogrow.input 说具有类 uiTextareaAutogrow 和类 input 的文本区域" –您真的有一个 textarea input ?

Your selector looks strange. textarea.uiTextareaAutogrow.input says "the textarea with class uiTextareaAutogrow and class input"--do you really have a textarea tag with the class input?

只要您的选择器正确,您可以尝试以下操作:

You could try this, provided your selector is correct:

var e = $.Event('keydown', { keyCode: 13 });
$('textarea.uiTextareaAutogrow.input').trigger(e);

这篇关于使用jQuery事件keydown模拟在textarea上输入不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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