gpt4 book ai didi

javascript - Opencart Filters添加onclick事件替换提交按钮

转载 作者:太空狗 更新时间:2023-10-29 14:16:09 26 4
gpt4 key购买 nike

我想向 Opencart 过滤器添加一个 onclick 事件,以替换隐藏在页面之外的提交按钮。我假设这应该使用 javascript/jquery 完成,但实现有点超出我的能力,可以你帮忙吗?

PHP:

<div class="box">
<div class="box-heading"><?php echo $heading_title; ?></div>
<div class="box-content">
<ul class="box-filter">
<?php foreach ($filter_groups as $filter_group) { ?>
<li><span id="filter-group<?php echo $filter_group['filter_group_id']; ?>"><?php echo $filter_group['name']; ?></span>
<ul>
<?php foreach ($filter_group['filter'] as $filter) { ?>
<?php if (in_array($filter['filter_id'], $filter_category)) { ?>
<li>
<input type="checkbox" value="<?php echo $filter['filter_id']; ?>" class="click_checkbox_manufacturers-filter" id="filter<?php echo $filter['filter_id']; ?>" checked="checked" />
<label for="filter<?php echo $filter['filter_id']; ?>"><?php echo $filter['name']; ?></label>
</li>
<?php } else { ?>
<li>
<input type="checkbox" value="<?php echo $filter['filter_id']; ?>" class="click_checkbox_manufacturers-filter" id="filter<?php echo $filter['filter_id']; ?>" />
<label for="filter<?php echo $filter['filter_id']; ?>"><?php echo $filter['name']; ?></label>
</li>
<?php } ?>
<?php } ?>
</ul>
</li>
<?php } ?>
</ul>
<a id="button-filter" class="button"><?php echo $button_filter; ?></a>
</div>
</div>

HTML 输出:

<div class="box">
<div class="box-heading">Refine Search</div>
<div class="box-content">
<ul class="box-filter">
<li><span id="filter-group2">Colour</span>
<ul>
<li>
<input type="checkbox" value="33" class="click_checkbox_manufacturers-filter" id="filter33">
<label for="filter33">Black</label>
</li>
<li>
<input type="checkbox" value="35" class="click_checkbox_manufacturers-filter" id="filter35">
<label for="filter35">Blue</label>
</li>
<li><span id="filter-group4">Scent Name</span>
<ul>
<li>
<input type="checkbox" value="64" class="click_checkbox_manufacturers-filter" id="filter64">
<label for="filter64">Almond</label>
</li>
<li>
<input type="checkbox" value="65" class="click_checkbox_manufacturers-filter" id="filter65">
<label for="filter65">Coconut</label>
</li>
</ul>
</li>
</ul>
<a id="button-filter" class="button">Refine Search</a>
</div>
</div>

JavaScript

<script type="text/javascript">
$('#button-filter').bind('click', function() {
filter = [];

$('.box-filter input[type=\'checkbox\']:checked').each(function(element) {
filter.push(this.value);
});

location = '<?php echo $action; ?>&filter=' + filter.join(',');
});
//--></script>

最佳答案

你可以这样做(而不是当前脚本):

<script type="text/javascript">
$(document).ready(function() {
// hide the "submit" button
$('#button-filter').hide();

// bind onChange event to the checkboxes
$('.click_checkbox_manufacturers-filter').live('change', function() {
filter = [];

$('.box-filter input[type=\'checkbox\']:checked').each(function(element) {
filter.push(this.value);
});

window.location = '<?php echo $action; ?>&filter=' + filter.join(',');
});
});
//--></script>

这里是 link to my JsFiddle完全相同的 JS 代码,令人惊讶的是 有效。唯一的问题可能是重定向...我编辑了上面的重定向代码,因此它应该也能正常工作。

关于javascript - Opencart Filters添加onclick事件替换提交按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19620662/

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