使用if else语句比较表格式的三个产品

时间:2016-10-07 11:47:52

标签: javascript if-statement

我正在做一个项目,我们必须使用Javascript在表格中并排比较三个项目。我已经定义了所有的值,现在我遇到了if / else语句的问题。我想要定义的是,如果第一列为空,则用第一组数据填充它。如果那里已有数据,则填充第2列。

有关格式等的任何建议将不胜感激。这是我目前的Js:

DOM.compare1[index].onclick = function(){

    if (DOM.compareCell1[index].innerHTML == "..."){ 
    compareColumn1.price.innerHTML = device1.price;
    compareColumn1.brand.innerHTML = device1.brand;
    compareColumn1.screenSize.innerHTML = device1.screenSize;
    compareColumn1.screenSurface.innerHTML = device1.screenSurface;
    compareColumn1.touchScreen.innerHTML = device1.touchScreen;
    compareColumn1.pixels.innerHTML = device1.pixels;
    compareColumn1.storage.innerHTML = device1.storage;
    compareColumn1.ssd.innerHTML = device1.ssd;
    compareColumn1.ram.innerHTML = device1.ram;
    compareColumn1.cpu.innerHTML = device1.cpu;
    compareColumn1.gpu.innerHTML = device1.gpu;
    compareColumn1.weight.innerHTML = device1.weight;
} 

else if ((DOM.compareCell1[index].innerHTML !== "..."){
    compareColumn2.price.innerHTML = device1.price;
    compareColumn2.brand.innerHTML = device1.brand;
    compareColumn2.screenSize.innerHTML = device1.screenSize;
    compareColumn2.screenSurface.innerHTML = device1.screenSurface;
    compareColumn2.touchScreen.innerHTML = device1.touchScreen;
    compareColumn2.pixels.innerHTML = device1.pixels;
    compareColumn2.storage.innerHTML = device1.storage;
    compareColumn2.ssd.innerHTML = device1.ssd;
    compareColumn2.ram.innerHTML = device1.ram;
    compareColumn2.cpu.innerHTML = device1.cpu;
    compareColumn2.gpu.innerHTML = device1.gpu;
    compareColumn2.weight.innerHTML = device1.weight;
}

0 个答案:

没有答案