我需要将类添加到 Opencart 搜索中的输入元素(在 header.tpl 中)
HTML 代码:
<input type="text" name="search" id="input-search" class=""/>
JQUERY 代码:
<script type="text/javascript">
$(document).ready(function() {
$("#input-search").keyup(function (e) {
if (e.keyCode == 13) {
$("#input-search").addClass("button-search");
}
});
});
</script>
我正在使用 Opencart,要重定向到搜索页面,您必须拥有 .button-search 类。我不想有提交按钮。
当我向输入添加一些文本,然后按 Enter 时,脚本应向输入添加类并重定向到 Opencart 搜索页面。
最佳答案
这就是你想要的,伙计。
代码:http://jsfiddle.net/webcarvers/xdt7g/1/ 预览:http://jsfiddle.net/webcarvers/xdt7g/1/embedded/result/
HTML
JS
$("#inputSearch").on('keypress',function (e) {
if (e.keyCode == 13) {
$("#inputSearch").addClass("buttonSearch");
$("p").text("Class added = " + $("#inputSearch").attr("class"));
window.location.replace("http://www.yahoo.com/")
}
});
关于javascript - 使用 jquery 搜索,无需提交按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22040414/