我正在尝试更改opencart标题中的搜索字段,以便在输入提交按钮后查找特定值。 这不是真的有效,但我无法弄清楚为什么。我错了什么?
这是我的代码: header.tpl
<div id="search">
<div class="button-search"></div>
<div><?php echo $text_search; ?></div>
<select name="filter_name" id="filter_name">
<option value="–">–</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<select name="filter_name" id="filter_name">
<option value="–">–</option>
<option value="pink">pink</option>
<option value="blue">blue</option>
<option value="red">red</option>
<option value="yellow">yellow</option>
<option value="green">green</option>
</select>
</div>
的header.php
if (isset($this->request->get['filter_name'])) {
$this->data['filter_name'] = $this->request->get['filter_name'];
} else {
$this->data['filter_name'] = '';
和common.js
$(document).ready(function() {
/* Search */
$('.button-search').bind('click', function() {
url = $('base').attr('href') + 'index.php?route=product/search';
var filter_name = $('input[name=\'filter_name\']').attr('value');
if (filter_name) {
url += '&filter_name=' + encodeURIComponent(filter_name);
}
var filter_name = $('#content select[name=\'filter_name\']').attr('value');
if (filter_name!='-') {
url += '&filter_name=' + encodeURIComponent(filter_name);
}
location = url;
});
$('#header input[name=\'filter_name\']').bind('keydown', function(e) {
if (e.keyCode == 13) {
url = $('base').attr('href') + 'index.php?route=product/search';
var filter_name = $('input[name=\'filter_name\']').attr('value');
if (filter_name) {
url += '&filter_name=' + encodeURIComponent(filter_name);
}
var filter_name = $('#content select[name=\'filter_name\']').attr('value');
if (filter_name!='-') {
url += '&filter_name=' + encodeURIComponent(filter_name);
}
location = url;
}
});