如何在jQuery mobile中按enter键时激活锚定标记

如何在jQuery mobile中按enter键时激活锚定标记,jquery,html,jquery-mobile,Jquery,Html,Jquery Mobile,我有一个搜索按钮,我想被执行,不仅当我点击它,而且当我按下回车键,以便更容易进行搜索。Im使用jQuery mobile显示搜索按钮,下面是HTML代码: <div data-role="popup" id="csr-popup-search" data-overlay-theme="a" data-theme="a" style="max-width:400px;" class="ui-corner-all"> <div data-role="content">

我有一个搜索按钮,我想被执行,不仅当我点击它,而且当我按下回车键,以便更容易进行搜索。Im使用jQuery mobile显示搜索按钮,下面是HTML代码:

<div data-role="popup" id="csr-popup-search" data-overlay-theme="a" data-theme="a" style="max-width:400px;" class="ui-corner-all">
    <div data-role="content">
        <div class="ui-grid-a" style="margin-top:0px;padding-top:0px;min-width:330px">
            <div class="ui-block-a" style="width:88%"><input type="search" name="search" id="search-basic" value="" placeholder="Search..."/></div>
            <div class="ui-block-b ui-responsive" style="width:10%;padding-top:3px;">
                <a href="#" data-role="button" data-iconpos="notext" data-theme="c" data-inline="true"  data-icon="search" onclick="ws.csr.search.run(this)">Search all</a></div>
        </div>

这就是我这边的情况:


我知道,使用按钮时,我只是简单地将其设置为type=“submit”,但在本例中,这不起作用,因为它是一个锚定标记

您可以在文档上收听按键。如果键是enter(键代码13),那么可以调用ajax

$(document).on("keyup", function (event) {
    if (event.which == 13) {
        $("#id-of-a-tag").click();
    }
});  

你可能想检查这个链接,试试这个
$('#search basic')。在(“keyup”,函数(e){if(e.keyCode==13)ws.csr.search.run(this);})
@Sushil谢谢你的回复,我把你的代码放在我的html页面底部,用包装,但它没有被执行,还有什么我需要做的吗?它被执行了吗?你得到了什么错误?谢谢,那么,我能把我的呼叫放在do东西里面吗,就像我现在做的那样?我的意思是这个调用:ws.csr.search.run(这个)您需要选择输入数据。更新了代码。它似乎被调用了(我在ChromeDevTools中看到了,但什么也没做)。不,与我单击按钮时相同。这是我想在按下enter键后使用的函数,如果有帮助的话:它只接受元素,而不是字段的值。您需要传入“a”标记,它应该像以前一样工作