Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
引导按钮;javascript_Javascript_Html_Twitter Bootstrap - Fatal编程技术网

引导按钮;javascript

引导按钮;javascript,javascript,html,twitter-bootstrap,Javascript,Html,Twitter Bootstrap,我的表格中有一段代码: <a onclick="discount()"><button class="btn btn-primary" style="background-color:#92CD00; color:black">Discount</button></a> 折扣函数按给定值降低价格 当我点击按钮时,折扣执行,但它立即闪烁回到原始值!为什么?请告诉我是否正确执行了按钮。您可以将功能、内容、行为、样式分离,并使用jQuery绑定按钮行为

我的表格中有一段代码:

<a onclick="discount()"><button class="btn btn-primary" style="background-color:#92CD00; color:black">Discount</button></a>
折扣函数按给定值降低价格


当我点击按钮时,折扣执行,但它立即闪烁回到原始值!为什么?请告诉我是否正确执行了按钮。

您可以将功能、内容、行为、样式分离,并使用jQuery绑定按钮行为

CSS样式:

#btn_discount {
    background-color: #92CD00;
    color: black;
}
HTML内容:

<button id="btn_discount" class="btn btn-primary">Discount</button>

呃。。。请发布您的代码。同意@Ennui。请发布折扣功能的代码。您的HTML无效。你不能在一个锚里面有一个按钮。@Quentin你有可以引用的来源吗?据我所知,这是可以接受的。可以包含.Content model:透明的任何内容,但不能有交互式内容子体-
$(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;
    }
};