【发布时间】:2014-06-23 12:51:32
【问题描述】:
这里是代码链接:jsfiddle demo
HTML 代码:
<div class="first">
<!-- Part one -->
<div class="acord_col">
<div class="img_class" id="exist_site"></div>
<div class="intro_text">
</div>
</div>
</div>
<div class='total_cost'>
<h1>Your Total Cost is: $<span class="cost_number">0</span><span class="cost_per_page no_display"> + 50/Page</span></h1>
</div>
Javascript
jQuery(document).ready(function() {
var total_price = 0;
jQuery("#exist_site").click(function() {
var bg = jQuery(this).css('background');
var check_string = 'yes.png';
if (bg.indexOf(check_string) > -1) {
jQuery(this).css({
'background': 'url("http://www.itechinstant.com/wp-content/uploads/2014/06/home.png")',
'background-size': 'cover'
})
total_price -= 200;
jQuery('.cost_number').empty().append(total_price);
jQuery("#exist_site").hover(function() {
jQuery(this).css({
'background': 'url("http://www.itechinstant.com/wp-content/uploads/2014/06/home_h.png)',
'background-size' : 'cover'
})
})
// Change the status of detected value
var boolean_next = parseInt(jQuery('.boolean_goNext').text());
boolean_next -= 1;
jQuery('.boolean_goNext').empty().append(boolean_next);
} else {
jQuery(this).css({
'background': 'url("http://www.itechinstant.com/wp-content/uploads/2014/06/yes.png")',
'background-size': 'cover'
})
total_price += 200;
jQuery('.cost_number').empty().append(total_price);
// Change the status of detected value
var boolean_next = parseInt(jQuery('.boolean_goNext').text());
boolean_next += 1;
jQuery('.boolean_goNext').empty().append(boolean_next);
}
})
})
我实际上是在使用 jquery 编写价格系统。
问题是它在谷歌浏览器中运行良好。但在 Firefox 和 IE11 中没有。
当我点击循环时,它应该增加成本,再次点击它应该取消选择循环并减去相同的成本。在 chrome 中一切正常。但是为什么在firefox和IE11中,无论我点击多少次,成本都在增加?
【问题讨论】:
-
可能应该读取
background-image属性,而不是组合的background属性。看起来每一次点击都会添加一个额外的.hover()事件处理程序,这不是你想要的。
标签: javascript jquery html css firefox