如何以编程方式调用标签列表上的click事件

问题描述 投票:0回答:1

我已经使用标签制作了燃油重量的“列表”,因为我想显示该列表在iOS设备上处于打开状态。这可以正常工作,我可以单击一个标签项目并获得重量(100)和弯矩(298.16)值。

接下来我想做的,我不知道怎么做,我想进行一次点击事件调用,并突出显示权重并将当前时刻也提取到变量中。

我该怎么做?

<label class="fuellist_click fuel_colors" data-fuel_moment="0.00">0</label>
<label class="fuellist_click fuel_colors" data-fuel_moment="298.16">100</label>
<label class="fuellist_click fuel_colors" data-fuel_moment="591.18">200</label>
<label class="fuellist_click fuel_colors" data-fuel_moment="879.08">300</label>
<label class="fuellist_click fuel_colors" data-fuel_moment="1165.42">400</label>
<label class="fuellist_click fuel_colors" data-fuel_moment="1448.40">500</label>

这是我手动单击燃油重量以获取重量和力矩值时的代码:

$('.fuelLoad').mousedown(function(event) {
    switch (event.which) {
        case 1:
            //Left Mouse button pressed
            $(this).val(fuel_weight);
            document.getElementById('idfuelLoadMoment').innerHTML = parseFloat(fuel_moment).toFixed(2);
            break;
        case 2:
            //Middle Mouse button pressed
            break;
        case 3:
            //Right Mouse button pressed
            $(this).val(0);// set value to 0
            return false;
            break;
        default:
    }
});
label
1个回答
0
投票

我重写了点击事件代码,该代码现在可以用来获取燃油重量和燃油力矩值:

function fuelListClick(obj) {
    fuel_weight = $(obj).text();
    fuel_moment = $(obj).data("fuel_moment");
    console.log("fuel_weight:" + fuel_weight);
    console.log("fuel_moment:" + fuel_moment);
}

现在,我需要能够调用具有特定燃料重量的点击事件,并使其在列表中选择该项目。

© www.soinside.com 2019 - 2024. All rights reserved.