【问题标题】:Press enter key on a web page在网页上按回车键
【发布时间】:2015-05-12 10:31:53
【问题描述】:

Fb 群组上有一个 texbox。这是html代码:

<input type="text" class="inputtext textInput" name="freeform" 
       placeholder="Gruba Başkalarını Ekle" autocomplete="off" aria-autocomplete="list" 
       aria-expanded="false" aria-owns="typeahead_list_u_jsonp_4_2" aria-haspopup="true" 
       role="combobox" spellcheck="false" aria-label="Gruba Başkalarını Ekle" 
       id="u_jsonp_4_3">

我使用 javascript 代码输入了一个名称。

document.getElementsByName('freeform')[0].value = '" + textBox2.Text + "';

但是没有按钮可以点击,我正在使用SendKeys.Send("{ENTER}") 事件点击enter

问题是 SendKeys.Send 对我来说不够用,我想用其他方式按 enter 键。

如何在不使用SendKeys.Send 的情况下按回车键?

【问题讨论】:

    标签: javascript jquery html click enter


    【解决方案1】:

    你可以很容易地在 jQuery 中实现这一点,方法是创建一个事件并分配回车键的 keyCode,即13

    var e = jQuery.Event('keydown');
    e.which = 13;
    $('input[name="freeform"]').trigger(e);
    

    【讨论】:

    • 我可以使用 javascript 代码代替 jQuery 吗?
    猜你喜欢
    • 2018-10-26
    • 2016-04-11
    • 1970-01-01
    • 1970-01-01
    • 2012-12-16
    • 2011-06-03
    • 2018-12-04
    • 1970-01-01
    • 2021-01-10
    相关资源
    最近更新 更多