新版本(不是新问题......)
所以,我遇到了 a.click();
和 a的“循环”问题.html();
。
检索 XML 数据:确定
function afficher(NomPizz, Prix1, Prix2, Prix3) {//HERE IS MY CODE//});
将它们打印到屏幕上:确定
$('#pricecontainer').show(); //Display my container and put values in with .html();
$('#prix1').html('SOLO 1P<p id="p1" style="line-height:10px;">' + Prix1.toFixed(2) + '</p>');
$('#prix2').html('MAXI 2P<p id="p2" style="line-height:10px;">' + Prix2.toFixed(2) + '</p>');
$('#prix3').html('SUPER 4P<p id="p3" style="line-height:10px;">' + Prix3.toFixed(2) + '</p>');
单击时将值附加到其他 div:OK但不是
一切正常...一次!当我单击更多次时,值“克隆”本身。
因此,如果我单击一次:我添加了 1 个项目。
我得到:1 好的
点击两次。
我得到了3 个,前一个和两个更多!
点击三下。
我得到了6 个,前三个和三个更多!
等等……等等……
我将此代码放入我function afficher();
找到的唯一一个解决方案中......糟糕的一个!
$("clickedItemId").click(function() {
var Figure = $(this).find('p').html();
totalArea.value += '+' + Figure;
var Screen = totalArea.value.replace(/'/g, ' ');
var result = eval(Screen);
totalArea.value = result;
var $newItem = "<span style='float:left'>1 " + NomPizz.toUpperCase() + "</span><span style='float:right'>" + Figure + "</span><br/>";
$('<div><div>').html($newItem).appendTo(RecapTick);
Display2.value = "TOTAL (EUR): " + totalArea.value;
$('#pricecontainer').hide();
});
所以,我function afficher();
遗嘱的全部代码是:
function afficher(NomPizz, Prix1, Prix2, Prix3) {
var totalArea = document.getElementById('totalArea');
var Display2 = document.getElementById('Display2');
var RecapTick = document.getElementById('MidTiTx');
$('#pricecontainer').show();
$('#prix1').html('SOLO 1P<p id="p1" style="line-height:10px;">' + Prix1.toFixed(2) + '</p>');
$('#prix2').html('MAXI 2P<p id="p2" style="line-height:10px;">' + Prix2.toFixed(2) + '</p>');
$('#prix3').html('SUPER 4P<p id="p3" style="line-height:10px;">' + Prix3.toFixed(2) + '</p>');
//BUG HERRERRERERERERER
$("clickedItemId").click(function() {
var Figure = $(this).find('p').html();
totalArea.value += '+' + Figure;
var Screen = totalArea.value.replace(/'/g, ' ');
var result = eval(Screen);
totalArea.value = result;
var $newItem = "<span style='float:left'>1 " + NomPizz.toUpperCase() + "</span><span style='float:right'>" + Figure + "</span><br/>";
$('<div><div>').html($newItem).appendTo(RecapTick);
Display2.value = "TOTAL (EUR): " + totalArea.value;
$('#pricecontainer').hide();
});
};
PS我住在这里旧版本的帖子(与其他代码相同的pb):
所以,我的问题如下:
[现场演示][1]
编辑: [下载源][2]
这是一个从 xml 文件中检索产品列表的简单购物车。这部分有效!
单击它们时,产品会添加到下面的列表中,但是当您重复单击相同的产品时,应该添加这些产品的总数......这就是我卡住的地方!
我试图更改第 62 行:
tot = parseInt(jQuery(this).find('.prow').html());
至:
tot = parseInt(jQuery(this).find('.prow').html()+1);
但不工作......我认为问题在于我正在使用。 。点击(); 使用onclick=""方法???或者可能是因为不好的“ var ”使用?
请有人赐教!
这是我的jsCode:
function calculate(){ var tot = 0; jQuery(".totprice").each(function(e,b){ tot += parseInt(jQuery(this).text()); }); return jQuery("#amt").html("$"+tot); } function showprod(){ jQuery(".prod").each(function(e){ jQuery(this).delay(500*e).fadeIn('fast'); }); } function clearcart(){ jQuery("#clear").live('click',function(){ jQuery(".tetew").fadeIn(4000,function(){ jQuery(this).remove(); calculate(); }); }); } function delete_ajax(){ jQuery(".del").live('click',function(e){ var a = jQuery(this); var p = a.parent().parent().parent().parent().parent(); if(p){ p.fadeOut('slow',function(){ jQuery(this).remove(); calculate(); }); } }); } function addtocart(){ jQuery(".addtocart").click(function(e){ var getprod = jQuery(this).attr("prodid"); var getval = jQuery(this).attr("prodval"); jQuery("#msg").fadeIn('slow'); jQuery.ajax({ type:'GET', url:'db.xml', dataType:'xml', success: function(xml){ jQuery(xml).find('databases').each(function(){ jQuery(this).find('prod').each(function(e){ var db_id = jQuery(this).attr('id'); jQuery("#msg").fadeOut('slow'); if(getprod == db_id){ var cookies = 1; jQuery(".tetew").each(function(){ var _this = jQuery(this); var _store = _this.find('.pstore'); var ident = _this.find('.pqty'); if(getprod == ident.text()){ var tot = parseInt(jQuery(this).find('.prow').html()); //Put a +1 here won't work... jQuery(this).find('.prow').html(tot); var restot = parseInt(jQuery(this).find('.prow').text()) * parseInt(jQuery(this).find('.price').text()); jQuery(this).find('.totprice').html(restot); cookies = 0; return false; }else{ cookies = 1; } }); if(cookies == 1){ var results = "<div class='tetew'>"; results +="<table>"; results +="<tr>"; results +="<td class='pqty' style='display:none' valign='top'>" + jQuery(this).attr("id") + "</td>"; results +="<td class='img' valign='top'><img src='" + jQuery(this).attr('img') + "' width='40' height='40' /></td>"; results +="<td class='pstore' valign='top'>" + jQuery(this).text() + "</td>"; results +="<td class='prow' valign='top'>1</td>"; results +="<td class='price' valign='top'>" + jQuery(this).attr('price') + "</td>"; results +="<td class='totprice' valign='top'>" + jQuery(this).attr('price') + "</td>"; results +="<td valign='top'><a href='javascript:void(0)' class='del'>Delete</a></td>"; results +="</tr>"; results +="</table>"; results +="</div>"; } jQuery(".tetew:eq("+e+")").hide().fadeIn('fast'); jQuery("#addto").append(results); calculate(); return false; } }); }); } }); }); } function loadXMLdb() { $.ajax({ type: "GET", url: "db.xml", dataType: "xml", success: function(xml) { $(xml).find('prod').each(function() { var _Nom = jQuery(this).text(); var Col1 = jQuery(this).attr('id'); var Col2 = jQuery(this).attr('price'); var Col3 = $(this).find('grand').text(); $('<div class="prod" style="display:block;" onclick="addtocart();"></div>').html(_Nom + '<br /><img
src="images/pizza.png">
Ajouter').appendTo(".vprod");}); } }); } jQuery(document).ready(function(){ showprod(); clearcart(); addtocart(); delete_ajax(); loadXMLdb(); });
[1]:http ://bzez.0fees.net/examples/jCart/ [2]: http ://bzez.0fees.net/examples/jCart/jCart.zip