计算平均值(Calculating averages)
我一直在努力计算2个不同列表中的平均值。 这是我一直在做的(作为python中的新手):
Averagelist = [] Listofvalues1 = ['1', '2', '3', '4'] Listofvalues2 = ['5', '6', '7', '8'] for i, x in enumerate(Listofvalues1): for j, y in enumerate(Listofvalues2): if j == i: AVGvalue = (int(x)+int(y)/2) Averagelist.append(AVGvalue)
我自己想出这种方式。 它可能没用,但到目前为止我可以打印我想要用于计算的两个值,但是我得到一个错误“ValueError:int(()的无效文字,基数为10:'somevalue'”。 这可能是
''
标志吗?干杯!
I've struggled with calculating average for values in 2 different lists. Here is what I have been doing (as newbie in python):
Averagelist = [] Listofvalues1 = ['1', '2', '3', '4'] Listofvalues2 = ['5', '6', '7', '8'] for i, x in enumerate(Listofvalues1): for j, y in enumerate(Listofvalues2): if j == i: AVGvalue = (int(x)+int(y)/2) Averagelist.append(AVGvalue)
I've come up with this way by myself. It might be useless, but so far I can print both values that I want to use for calculation but I get an error "ValueError: invalid literal for int() with base 10: 'somevalue'". Could it be the
''
sign?Cheers!
原文:
最满意答案
var td = $('td[art_id="4949"]');
如果变量中有
art_id="4949"
,var art_id="4949"; var td = $('td[art_id="' + art_id +'"]');
然后单击元素,您可以使用
get(index)
检索底层DOM元素,然后触发本机click()
td.get(0).click();
注意:我建议使用
data-*
前缀自定义属性来存储元素的任意数据。You can use Attribute Equals Selector [name=”value”]
var td = $('td[art_id="4949"]');
If have
art_id="4949"
in a variable,var art_id="4949"; var td = $('td[art_id="' + art_id +'"]');
Then to click element, you can use
get(index)
to retrieve the underlying DOM element then to trigger nativeclick()
td.get(0).click();
Note: I would recommend to use
data-*
prefixed custom attribute to store arbitrary data with the element.
相关问答
更多-
Jquery在点击子td内的链接时遍历父表(Jquery iterate through the parent table on click of a link within a child td)[2022-12-31]
也许尝试以下方法: function event_a() { $(".ptable").find("td").bind("click",{nr:index},function(evt){ alert(evt.data.nr); }); } 您可以通过以下方式将此函数绑定到每个a-tag: $(".abc a").click(event_a); Just don"t want to keep it unanswered. as I have one solution I w ... -
您可以在事件对象上使用target属性并检查它是否具有类exclude 。 $('tr').click(function(e) { if (!$(e.target) .parents() .andSelf() .hasClass('exclude')) { alert('Click') } }) td { border: 1px solid black; padding: 5px; }