获取位于表jquery中的输入字段的值

时间:2017-01-05 23:27:10

标签: javascript jquery html css

这应该是受jeasyui.com启发的购物车。我有三个问题。

  1. 在输入框中更改数量时,我无法获得数量的值。
  2. 当我从购物车中删除某个商品时,该服务必须再次在相应的标签中提供。
  3. 每个新标签的服务都会缩进。我每次都需要他们从头开始。
  4. 这是我到目前为止的代码:codepen.io。对不起,如果它很乱,这是我第一次使用javascript / jquery。任何帮助表示赞赏。谢谢!

    function removeProduct(el) {
     var name1 = $(el).closest('tr').find('td').eq(0).text();
     var price1;
     for (var i = 0; i < data.length; i++) {
       if (name1 == data[i][0]) {
       price1 = data[i][2];
     }
       var className = $(el).parent().attr('class');
       /**Add a new list item in item class with the class name and the service name and price in paragraphs.*/
       $(el).closest('tr').remove();
     }
    }
    
    function changeQuantity(el) {
    var name1 = $(el).closest('tr').find('td').eq(0).text();
    var quantity1 = $(el).closest('tr').find('td').eq(1).value;
    var price1;
    for (var i = 0; i < data.length; i++) {
      data[i][1] = quantity1;
      data[i][2] = price * quantity1;
      if (name1 == data[i][0]) {
        price1 = data[i][2];
      }
    }
     $(el).closest('tr').find('td').eq(1).html("<input type='number' value='" + quantity1 + "' style='width:100%;'>");
     $(el).closest('tr').find('td').eq(3).html(price1);
    }
    

1 个答案:

答案 0 :(得分:0)

获取数量:

$(el).closest('tr').find('td').eq(1).find('input').val();

因为您使用source.remove();从DOM中物理删除元素,所以您无法轻松完成。我建议在隐藏它的元素中添加一个类。然后当您从卡中删除它时,删除该类。

对于第三个问题,请删除隐藏产品类的CSS,然后添加:

卸下:

.Biostatistics {
    display: none;
}
.ClinicalLaboratory {
    display:none;
}
.Something{
    display:none;
}

添加:

.Products li {
    display: none;
}

同样将你的js更改为这样(添加最接近的('li'):

x[i].closest('li').style.display = 'none';
相关问题