Javascript jquery在相同的环境中使用不同的变量<;p>;来自数据库中的字段
Javascript jquery在相同的环境中使用不同的变量<;p>;来自数据库中的字段,javascript,php,jquery,Javascript,Php,Jquery,我有一个问题,我不能在我的购物车中放入不同的数量,因为当我选择一个数量时,程序会根据我选择的数量进行计算,结果是为了钱等(在这里工作正常),并将数量带到名为“encomenda”的购物车中,但当我添加不同的项目时,数量会更改为全部,而不是仅更改为一个,从我的英语中学习英语 //购物车html carrinho 安科门达 {数据%中的项的%1} {{item.marca | e}} {{item.descr | e}} {{item.preco|u unit{e}}€ **//显示此处的金额**
我有一个问题,我不能在我的购物车中放入不同的数量,因为当我选择一个数量时,程序会根据我选择的数量进行计算,结果是为了钱等(在这里工作正常),并将数量带到名为“encomenda”的购物车中,但当我添加不同的项目时,数量会更改为全部,而不是仅更改为一个,从我的英语中学习英语 //购物车html
carrinho
安科门达
{数据%中的项的%1}
{{item.marca | e}}
{{item.descr | e}}
{{item.preco|u unit{e}}€
**//显示此处的金额**
{{item.preco|u unit{e}}€
{{item.preco_单元}
{%endfor%}
0
//例如添加迪斯科舞厅
$('.adicionar disco')。单击(函数(){
id=$(this.data('id');
var allExceptClicked=$('.adicionar disco')。不是(这个);
AdicionarItem(allexcept,“disco”,“disco2”);
$(this.data('quantidade',parseFloat($(this.parent().find(“span.qt”).text());
$(this.parent().parent().find(“button.close disco”).data($(quantidade),parseFloat($(this.parent().find(“span.qt”).text());
preco=preco+($(this).data(“preco”)*$(this.data('quantidade'));
p=$(this).data('quantidade');**//在p中接收金额**
var取整=数学取整((preco)*100)/100;
$('valor#u').html(四舍五入);
$('.adicionar encomenda')。每个(函数(){
var productRow=$(this.parent().parent();
var i=$(this.data('id');
如果(i==id){
productRow.show();
警惕(p);
$(“.quantidade”).text(p);**//给出“encomenda”p中包含所需数量的变量**
//$(“p”).attr(“.quantidade”,p);
//Marcar项目como selecionado
$(this.attr(“数据选择”,“sim”);
}
});
});
语句$(“.quantidade”).text(p)
使用class=“quantitade”在所有元素上设置相同的值,并且图表的所有项目都有class=“quantitade”。
您应该使用id属性唯一地标识要设置值的div,如果可能,使用产品id生成。html代码在哪里?您的问题令人困惑。你能简单解释一下吗?我将编辑并添加我的html代码显示的内容而不是期望的结果。此外,这里没有PHP,因此您可以删除该标记。当我选择一个数量时,程序会根据我选择的内容进行计算,并将结果用于金钱等(在这里运行良好),然后将数量带到名为“encomenda”的购物车中,但当我添加不同的项目时,数量将更改为全部,而不是仅更改为一个,ssry来自我的英语,但它显示在同一个div中,是添加的所有div的一个div,明白吗?您为购物车中的每个元素创建
。然后使用class='quantitade',使用语句$(“.quantidade”).text(p)
在每个元素中设置一个值,所有这些元素的值相同。
<div class="rightdiv">carrinho
<div id="encomenda" class="expandContent">
<h3 class="header">
<div class="headerColumn1">Encomenda</div>
<div class="headerColumn2 expand"><img src="img/plus.png"/></div>
<div class="expandedContentClearFloat"></div>
</h3>
<div class="expandedContent">
{% for item in data %}
<div class="product-removal">
<article class="product">
<header>
<img src="{{ item.img|e }}" class="iconcomp">
</header>
<div class="content">
<h1>{{ item.marca|e }}</h1>
{{ item.descr|e }}
</div>
<footer class="content">
<h2 class="full-price fixed fixed-encomenda">
{{ item.preco_unit|e }}€
</h2>
<p class='quantidade' ></p> **//shows the amount here**
<a class='pull-right adicionar adicionar-encomenda' data-id='{{ item.id|e }}'
data-preco='{{ item.preco_unit|e }}' data-modelo="{{ item.modelo|e }}" data-marca="{{ item.marca|e }}" data-descr="{{ item.descr|e }}">
<h2 class="full-price">
{{ item.preco_unit|e }}€
</h2>
</a>
<h2 class="price">
{{ item.preco_unit|e }}
</h2>
</footer>
</article>
</div>
{% endfor %}
<h1 id='valor_configuracao' class='pull-right' value='data-preco'>0</h1>
</div>
<input type="button" id="enviar" value="enviar" data-mensagem="ola">
</div>
</div>
$('.adicionar-disco').click(function () {
id = $(this).data('id');
var allExceptClicked = $('.adicionar-disco').not(this);
AdicionarItem(allExceptClicked, "disco", "disco2");
$(this).data('quantidade', parseFloat($(this).parent().find("span.qt").text()));
$(this).parent().parent().find("button.close-disco").data('quantidade', parseFloat($(this).parent().find("span.qt").text()));
preco = preco + ($(this).data("preco")* $(this).data('quantidade'));
p=$(this).data('quantidade'); **//receive in p the amount**
var rounded = Math.round((preco) * 100) / 100;
$('#valor_configuracao').html(rounded);
$('.adicionar-encomenda').each(function () {
var productRow = $(this).parent().parent();
var i = $(this).data('id');
if (i == id) {
productRow.show();
alert(p);
$(".quantidade").text(p);**//give the <p> variable that is in the "encomenda" p that has the amount needed**
//$("p").attr(".quantidade",p);
//Marcar item como selecionado
$(this).attr("data-selecionado","sim");
}
});
});