我在我的网站上使用.change()函数,点击这里,用户可以选择他们产品的数量。我的问题是我的图表只是把我的自我和12包联系起来,而不是六块。我已经签入了firebug,我注意到JS已经创建了两个按钮,我相信链接到6 pack的按钮开始与12 pack的按钮重叠。
最终,我希望按钮链接改变相对于价格。有人知道我需要在下面添加什么代码才能实现这一点吗?
我只有一个链接按钮,我使用表达式引擎,所以第二个是自动创建的
<script type="text/javascript">
var message = new Array();
message[1] = "$15.00";
message[2] = "$25.00";
$(document).ready(function(){
$("#item_select").change(function()
{
var message_index
message_index = $("#item_select").val();
$(".price-item h3").empty();
if (message_index > 0)
$(".price-item h3").append(message[message_index]);
});
});
</script>
{p_cartlink}
<a href="http:// class="button_atc atc_{url_title}"></a>
{/p_cartlink}问题是,由于这段代码是用于模板的,所以我不希望您使用我需要使用的产品名SLEEP-12 and SLEEP-6。是为JS中的每个按钮创建一个需要ID的方式,然后启用和禁用该按钮。例如,当您选择6包时,会出现6 pack按钮,并禁用12 pack吗?
发布于 2012-10-03 23:13:19
你可以这样做
$(document).ready(function() {
$("#item_select").change(function() {
var message_index
message_index = $("#item_select").val();
// get the correct button
var $button = $('.price-item right .button_atc').eq(message_index-1);
// hide button - not the correct one
$('.price-item right .button_atc').not($button).hide();
// show correct button
$button.show();
$(".price-item h3").empty();
if (message_index > 0) $(".price-item h3").append(message[message_index]);
});
});发布于 2012-10-03 23:06:27
而不是有两个链接按钮在您的页面,我将只有一个。然后,当索引发生变化时,我将更新该链接按钮的href属性。
发布于 2012-10-03 23:18:18
这变成了一个非常丑陋的黑客和未经测试的代码,但我偷它应该能工作。
请试一试,如果您有什么问题,请告诉我:
<script type="text/javascript">
var message = ["$15.00","$25.00"];
$(document).ready(function(){
// Init to make sure we display the correct button @ load
$("#item_select").trigger('change');
// The change-function
$("#item_select").on('change'.function() {
var message_index = $("#item_select").val();
var message_indexn = message_index.split(' ');
var message_id = 0;
for ($i = 0; i < message_indexn.length; i++) {
if (/^[\d]+$/.test(message_indexn[i])) {
message_id = message_indexn[i];
break;
}
}
$(".price-item h3").empty();
if (message_index > 0)
$(".price-item h3").append(message[message_index-1]);
$('.price-item .button_atc').each(function () {
if ($(this).attr('href') == 'http://store.bodyworksforme.com/ShoppingCart.asp?ProductCode=SLEEP-'+message_id) {
if ($(this).is(':hidden'))
$(this).show();
}
else {
if ($(this).is(':visible'))
$(this).hide();
}
});
});
});
</script>https://stackoverflow.com/questions/12718067
复制相似问题