我无法理解。 。当我点击具有唯一ID的特定事件时,我需要获取该ID的名称,但是目前我获得了所有ID的同名信息。有关说明,请参阅以下注释
function update(){
//this is the array of database values
dbvalues = dbvalues.split("~"); //dbvalues[i+0], dbvalues[i+1]....
//I have a label which have values form database
var dblabel = '<br/><label class="addevents" id="' + dbvalues[i+3] + '">'+dbvalues[i+2]+ " " + dbvalues[i+4] +'</label>';
//this variable holds all the event name that are in database.
var g =dbvalues[i+2];//eg: meeting, lunch, dinner
//now this is the the real function, I am getting ID of the label, when I click on particular ID it needs to show name of that particular ID, but currently whichever event I click it shows same name for all the IDS.
var el = document.getElementById((dbvalues[i+3]));
el.onclick = function () {
alert(g); //it is showing same name for all the ID'S clicked.
};
};
&#13;
答案 0 :(得分:1)
您无法使用此方式使用Var g值因为可以更改所有时间变量值。 因此,当您单击元素时,元素在那时只有最后添加的值可用于所有var g所以您可以为所有元素获得相同的值。 在那个时候如果你想这样做你可以尝试使用 Html data attr 这样
public Class1()
{
products.add(new Product("Big Phone", 200.00, PHONE));
products.add(new Product("Small Phone", 50.00 , PHONE));
products.add(new Product("Aftermarket Charger", 10.00, CHARGER));
products.add(new Product("Original Charger", 20.00, CHARGER));
products.add(new Product("Case", 20.00, ACCESSORIES));
products.add(new Product("Other Accessories", 60.00 , ACCESSORIES));
}
public LinkedList<Product> products(Category category){
for (Product product : products)
if (product.matches(category))
return products;
return null;
}
你的点击代码看起来像这样
Public class Class4 {
public class createOrder {
System.out.print.ln("Creating new order")
}
}