你可以分開你的功能(內容,行爲,樣式),並用jQuery綁定你的按鈕行爲。
CSS(樣式):
#btn_discount {
background-color: #92CD00;
color: black;
}
HTML(含量):
<button id="btn_discount" class="btn btn-primary">Discount</button>
JS(行爲):
$(document).ready(function() {
$("#btn_discount").click(
var current_price = my_app.get_price();
var discount_value = my_app.get_discount();
var new_price = my_app.discount(current_price, discount_value);
my_app.set_price(new_price);
);
});
var my_app = {
price: 0,
discount: 0,
get_price: function() {
return this.price;
},
set_price: function(new_price) {
this.price = new_price;
},
get_discount: function() {
return this.discount_value;
},
set_discount: function(new_discount_value) {
this.discount = new_discount_value;
},
discount: function(price, value) {
var reduced_price;
....
return reduced_price;
}
};
呃......發佈您的代碼,請。 – Ennui
同意@Ennui。請發佈您的「折扣()」功能的代碼。 –
您的HTML無效。錨點內不能有按鈕。 – Quentin