複数のdiv( "show" + i)に同時に機能を割り当てたい場合、それぞれの呼び出しは別のdiv( "theDiv" + i)、 "+ i"は機能しません。
$("#show"+i).click(function()
{
$("#theDiv"+i).show("normal");
});
"i"の値(0,1,2 ...)を再配置すると、コードは機能しています。では、なぜこれを修正できますか? これは全体の機能である:
function getInfoProduits1()
{
var request = new XMLHttpRequest();
if(i<idProduits.length)
{
request.open("GET","http://patisserie-orient.fr/prestashop/prestashop/api/products/"+idProduits[i]+"?PHP_AUTH_USER="+PHP_AUTH_USER+"&ws_key="+ws_key,true);
request.onreadystatechange = function()
{
if(request.readyState==4)
{
//alert("Status2 is "+request.status);
if (request.status == 200 || request.status == 0)
{
response1 = request.responseXML.documentElement;
nameProduits[i] = response1.getElementsByTagName('name')[0].getElementsByTagName('language')[0].firstChild.data;
//alert(nameProduits[i]);
priceProduits[i] = response1.getElementsByTagName('price')[0].firstChild.data+" €";
//alert(priceProduits[i]);
descriptionProduits[i] = response1.getElementsByTagName('description_short')[0].getElementsByTagName('language')[0].firstChild.data;
//alert(descriptionProduits[i]);
quantitieProduitsDisponible[i] = response1.getElementsByTagName('quantity')[0].firstChild.data;
//alert(quantitieProduitsDisponible[i]);
maDiv = document.createElement("div");
maDiv.id = 'id_de_la_div'+i;
malabel = document.createElement("div");
malabel1 = document.createElement("div");
mon_bouton1 = document.createElement("button");
maDiv2 = document.createElement("div");
mon_bouton1.id="show"+i;
maDiv2.id="theDiv"+i;
maDiv2.innerHTML="Détails:";
maDiv2.style.display="none";
//mon_bouton1.value='click';
$("#show"+i).click(function(){
$("#theDiv"+i).show("normal");
});
mon_bouton1.onclick='aff();';
malabel.innerHTML=nameProduits[i];
malabel1.innerHTML=priceProduits[i];
maDiv.innerHTML='<img src="Images/Icones/dollars.png" width="50" height="50" align="right">';
//maDiv.innerHTML='<button type="button" id="show" onclick="aff();">Détails</button> ';
maDiv.className="ui-bar ui-bar-e cadre";
document.getElementById("divbar").appendChild(maDiv);
document.getElementById('id_de_la_div'+i).appendChild(malabel);
document.getElementById('id_de_la_div'+i).appendChild(malabel1);
document.getElementById('id_de_la_div'+i).appendChild(mon_bouton1);
document.getElementById('id_de_la_div'+i).appendChild(maDiv2);
maDivvide = document.createElement("div");
maDivvide.innerHTML='<br>';
document.getElementById("divbar").appendChild(maDivvide);
i++;
getInfoProduits1();
}
}
}
request.send();
}
else
{
return;
}
}
どのように定義されていますか?関連するコードを投稿できますか? – j08691
機能の詳細を表示してください私たちは 'i'の初期化を検証することができますので。 – Fourth
初期化して値を 'i'に割り当てるコードを投稿できますか? –