__('Searc-6ren">
gpt4 book ai didi

javascript - 如何禁用搜索栏上的回车键

转载 作者:行者123 更新时间:2023-11-28 05:05:10 25 4
gpt4 key购买 nike

我正在使用 Magento,并且想要禁用搜索栏上的 Enter 键。我的搜索栏代码如下:

<form id="search_mini_form" action="<?php echo $catalogSearchHelper->getResultUrl() ?>" method="get">
<div class="input-box">
<label for="search"><?php echo $this->__('Search:') ?></label>
<input id="search" type="search" name="<?php echo $catalogSearchHelper->getQueryParamName() ?>" value="<?php echo $catalogSearchHelper->getEscapedQueryText() ?>" class="input-text required-entry" maxlength="<?php echo $catalogSearchHelper->getMaxQueryLength();?>" placeholder="<?php echo $this->quoteEscape($this->__('Search entire store here...')) ?>" />
<button type="submit" title="<?php echo $this->quoteEscape($this->__('Search')) ?>" class="button search-button"><span><span><?php echo $this->__('Search') ?></span></span></button>
</div>

<div id="search_autocomplete" class="search-autocomplete"></div>
<script type="text/javascript">
//<![CDATA[
var searchForm = new Varien.searchForm('search_mini_form', 'search', '');
searchForm.initAutocomplete('<?php echo $catalogSearchHelper->getSuggestUrl() ?>', 'search_autocomplete');
//]]>
</script>
</form>

关于如何做到这一点有什么想法吗?

最佳答案

使用JQuery in Magento :

$('#search_mini_form').on('keyup keypress', function(event) {
var key = event.keyCode || event.which;
if (key === 13) {
event.preventDefault();
return false;
}
});

将其放入模块的layout.xml中的默认标签下:

<layout>  
<default>
<reference name="head">
<action method="addJs">
<script>custom.js</script>
</action>
</reference>
</default>
</layout>

关于javascript - 如何禁用搜索栏上的回车键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41809463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com