如何使用JavaScript中作为函数参数动态创建的输入框的ID?

时间:2018-09-25 12:04:24

标签: javascript javascript-events event-handling addeventlistener

我的原始HTML代码如下:

if('TranseferType' = 1 ) Then
   SELECT 'StartDate' FROM tablename WHERE yourcolumn;
else if('Current' = 'Yes')
    SELECT 'StartDate' FROM tablename WHERE yourcolumn;
 end if;
function GrossWeight() {
    var loaded = document.getElementById('loaded').value;
    var empty = document.getElementById('empty').value;
    document.getElementById('grossweight').value = (parseFloat(loaded) || 0) - (parseFloat(empty) || 0);
}

现在,通过单击<div class="row"> <div class="col-md-4 col-sm-12 col-lg-4 col-xs-12"> <div class="form-group" style="background-color: white"> <label>Load Truck Weight:</label> <input id="loaded" runat="server" clientidmode="Static" type="number" text="0" onchange="GrossWeight()" class="form-control" step="any" style="width: 200px;" /> </div> </div> <div class="col-md-4 col-sm-12 col-lg-4 col-xs-12"> <div class="form-group" style="background-color: white;"> <label>Empty Truck Weight:</label> <input id="empty" runat="server" clientidmode="Static" type="number" text="0" onchange="GrossWeight();calculatefreight();" step="any" class="form-control" style="width: 200px;" /> </div> </div> <div class="col-md-4 col-sm-12 col-lg-4 col-xs-12"> <div class="form-group" style="background-color: white"> <label>Gross Weight :</label> <input id="grossweight" runat="server" clientidmode="Static" type="text" placeholder="0" class="form-control" style="width: 150px; font-weight: bold;" readonly="readonly" /> </div> </div> </div> enter code here,上面提到的三个框将以button(Provided)之类的递增ID继续动态生成。 通过事件委托,有什么方法可以对那些动态创建的函数执行相同的算术运算吗?

0 个答案:

没有答案