Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/444.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/0/jpa/2.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 jquery单击并减去_Javascript_Jquery - Fatal编程技术网

Javascript jquery单击并减去

Javascript jquery单击并减去,javascript,jquery,Javascript,Jquery,我有个问题 当点击.aa时,它会生成元素,并在seattist['seats'][column][row]['price']的帮助下计算价格并以$(“.checkout\u area”)显示一般价格。 每个按钮中都有一个$(“.desc2 a”)按钮,当点击它时,它应该从一般价格中减去座位列表['seats'][列][行]['price'],并显示在$(“.checkout\u区域”),我已经写在那里了,但我不知道为什么,它不起作用 你有什么建议吗。 多谢各位 var ipl = 1;

我有个问题

当点击.aa时,它会生成元素,并在
seattist['seats'][column][row]['price']
的帮助下计算价格并以
$(“.checkout\u area”)显示一般价格。

每个按钮中都有一个
$(“.desc2 a”)
按钮,当点击它时,它应该从一般价格中减去
座位列表['seats'][列][行]['price']
,并显示在
$(“.checkout\u区域”)
,我已经写在那里了,但我不知道为什么,它不起作用

你有什么建议吗。 多谢各位

    var ipl = 1;
    var price = 0;
    var createNewElem = function(obj) {
        var column = obj.parent().children().index(obj.get(0));
        var row = obj.parent().parent().children().index(obj.get(0).parentNode);
        ++ipl;

        if (!$(obj.attr("rel")) || $(obj.attr("rel")).size() < 1) {
            obj.attr("rel", "#cc_" + ipl);
            $(".seat_desc")
                .append("<div id='cc_" + ipl + "' class='desc2'>" +
                "<p class='section_s'>" + seatlist['seats'][column][row]['sector'].replace(/sector\s/, '') + "</p>" +
                "<p class='row_r'>" + seatlist['seats'][column][row]['row'].replace(/Row\s/, '') + "</p>" +
                "<p class='seat_s'>" + seatlist['seats'][column][row]['seat'].replace(/seat\s/, '') + "</p>" +
                "<a href='#'>remove</a>" +
                "<span> CA $" + seatlist['seats'][column][row]['price'] + "</span>" +
                "<div class='clear'></div>" +
                "</div>");
            price += seatlist['seats'][column][row]['price'];
            $(".checkout_area").html("SUBTOTAL: CA $" + price);
        } else {
            $(obj.attr("rel")).remove();
            obj.attr("rel", "");
             price -= seatlist['seats'][column][row]['price'];
            $(".checkout_area").html("SUBTOTAL: CA $" + price);
        }
    };

    $(".aa").click(function() {
        createNewElem($(this));
    });

$(".desc2 a").live("click", function() {
        var column = $(this).parent().children().index(this);
       var row = $(this).parent().parent().children().index(this.parentNode);
        $(this).parent("div").remove();
        $(".seat p span").html($(".desc2").length);
       $(".checkout_area").html("SUBTOTAL: CA $" + price - seatlist['seats'][column][row]['price']);
        return false;
    });
var-ipl=1;
var价格=0;
var createNewElem=函数(obj){
var column=obj.parent().children().index(obj.get(0));
var row=obj.parent().parent().children().index(obj.get(0.parentNode));
++ipl;
if(!$(对象属性(“rel”))|$(对象属性(“rel”)).size()<1){
目标属性(“rel”、“cc”+ipl);
$(“.seat_desc”)
.append(“)+
“

”+座位列表['seats'][列][行]['sector']。替换(/sector\s/,'')+”

”+ “

”+座位列表['seats'][column][row]['row']。替换(/row\s/,'')+”

”+ “

”+座位列表['seats'][列][行]['seat']。替换(/seat\s/,'')+”

”+ "" + “CA$”+座位列表['seats'][列][行]['price']+“”+ "" + ""); 价格+=座位列表['seats'][列][行]['price']; $(“.checkout_area”).html(“小计:CA$”+价格); }否则{ $(对象属性(“rel”)).remove(); 对象属性(“rel”、“rel”); 价格-=座位列表['seats'][列][行]['price']; $(“.checkout_area”).html(“小计:CA$”+价格); } }; $(“.aa”)。单击(函数(){ createNewElem($(this)); }); $(“.desc2 a”).live(“单击”,函数(){ var column=$(this.parent().children().index(this); var row=$(this.parent().parent().children().index(this.parentNode); $(this.parent(“div”).remove(); $(.seat p span”).html($(.desc2”).length); $(“.checkout_area”).html(“小计:CA$”+价格-座位列表['seats'][列][行]['price']); 返回false; });
很难从您的问题中准确地知道出了什么问题,但您可以尝试对这两个值进行
parseFloat
-

$(".desc2 a").live("click", function() {
        var column = $(this).parent().children().index(this);
       var row = $(this).parent().parent().children().index(this.parentNode);
        $(this).parent("div").remove();
        $(".seat p span").html($(".desc2").length);
       $(".checkout_area").html("SUBTOTAL: CA $" + parseFloat(price) - parseFloat(seatlist['seats'][column][row]['price']);
        return false;
    });

您正在将算术与非数字字符串表达式混合使用。 做点像

 var t=  price - seatlist['seats'][column][row]['price'];
 $(".checkout_area").html("SUBTOTAL: CA $" + t ); 
编辑 在使用firebug查看代码之后,行列计算似乎会导致seatlist数组中出现未定义的元素。我加了一个座位,并试图把它移走。它试图减去的元素在座位列表中未定义。i、 在我的例子中{col=3 row=1 seatlist['seats'][3][1]['price']=undefined}根据Firebug。 因此,主要的问题不在计算行中(尽管如果你想做正确的算术,答案是正确的)。
我建议使用Firebug或Chrome开发工具。毕竟我们不能为你调试你的代码

我们需要附带的HTML来查看示例$(“.desc2 a”).live(“单击”,function(){var column=$(this.parent().children().index(this);var row=$(this.parent().parent().children().index(this.parentNode);$(“.checkout_area”).HTML(“小计:CA$”+price-seatlist['seats'][column][row][price']);返回false;});它是dos'nt work$(“.checkout_area”).html(“小计:CA$”+价格-座位列表['seats'][列][行]['price']);你认为parseFloat是什么,但你能解释一下parseFloat的成因吗?
var t=  price - seatlist['seats'][column][row]['price'];
$(".checkout_area").html("SUBTOTAL: CA $" + t );