onClick中的“this”如何工作?(How does “this” in onClick work?)
我是新来的JavaScript。 我很好奇浏览器如何使
onClick
属性起作用。 你有这样的HTML:<button id="1" onClick="reply_click(this.id)">B1</button>
浏览器执行什么(allways javascript?)脚本功能?
我想这是类似评估给予onClick的字符串。
但我怀疑这些:这里的适用标准是什么? 浏览器如何知道使用哪种脚本语言? javascript引擎是如何填充的? 脚本在什么情况下执行? 返回值会发生什么? 我想读什么知道在使用这些属性时可以依靠什么?
你能帮我理解发生了什么吗?
I'm new to javascript. I'm curious how does the browser makes an
onClick
attribute work. You have this in a html:<button id="1" onClick="reply_click(this.id)">B1</button>
what does a browser do to execute a the (allways javascript?) script function?
I guess this is something like eval-ing the string that is given to the onClick.
But I have doubts like these: What is the applying standard here? How does the browser know which script language to use? How is
this
filled up by the javascript engine? In what context does the script execute? What happens with a return value? What do I want to read to know what can I rely on when working with these attributes?Can you help me to understand what's going on?
原文:https://stackoverflow.com/questions/19589220
最满意答案
要将第一个元素捕获到变量中,可以使用列表推导,如:
码:
data = { 'ID': [[310.5, 1.1612828], [310.0, 15.0], [310.0, 2.9755309], [309.5, 30.0]] } variable = [x[0] for x in data['ID']] print(variable)
结果:
[310.5, 310.0, 310.0, 309.5]
To capture the first elements into a variable, you can use a list comprehension like:
Code:
data = { 'ID': [[310.5, 1.1612828], [310.0, 15.0], [310.0, 2.9755309], [309.5, 30.0]] } variable = [x[0] for x in data['ID']] print(variable)
Results:
[310.5, 310.0, 310.0, 309.5]
相关问答
更多-
返回包含在另一个列表中的Python列表中的第一项(Returning the first item in a Python list which is contained in another list)[2021-08-30]
您可以使用生成器表达式和'next()'函数。 示例 - def FindFirstMatch(list1, list2): """ Returns the first element in list "list1" for which there is a matching element in list "list2" or None if there is no match """ setb = set(list2) return next((ite ... -
我会这样做: Count[Split[{1, 1, 1, 0, 1}][[All, 1]], 1] 要么 Total[First /@ Split[{1, 1, 1, 0, 1}]] I'd do this: Count[Split[{1, 1, 1, 0, 1}][[All, 1]], 1] or Total[First /@ Split[{1, 1, 1, 0, 1}]]
-
使用列表解析 : >>> lst = [['a','b','c'], [1,2,3], ['x','y','z']] >>> lst2 = [item[0] for item in lst] >>> lst2 ['a', 1, 'x'] Using list comprehension: >>> lst = [['a','b','c'], [1,2,3], ['x','y','z']] >>> lst2 = [item[0] for item in lst] >>> lst2 ['a', 1, 'x']
-
切片列表返回一个新的列表对象,它是您在切片中指示的原始列表索引的副本。 然后,您反弹lst (函数中的本地名称)来引用该新列表。 在这个过程中,旧名单永远不会改变。 list.pop()另一方面对列表对象本身进行操作。 无论您使用什么参考资料来访问该列表,都没有关系。 你会看到没有功能的相同的东西: >>> a = [1, 2] >>> b = a[:] # slice with all the elements, produces a *copy* >>> b [1, 2] >>> a.pop() # ...
-
import bisect L = [(0, "test", "value"), (1, "test2", "value2"),(3,"test3","value3")] print (bisect.bisect_left(L,(2,))) python处理元组比较很好......只是通过它(2,"asd","dsa")或者甚至只是(2,) (或者你试图找到的任何索引位置项) 或者你可以传递它(0,"asd","value") ,它会知道把它放在另一个(0,"test","value")项目元组左侧或者( ...
-
您不必首先计算所有组合。 从整个列表开始。 然后尝试长度为“list_length - 1”的所有子列表,然后尝试长度为“list_length - 2”的所有子列表,依此类推。 只要您获得满足要求的列表,就可以摆脱循环。 无需尝试更短的列表。 def max_length(input_list): input_length = len(input_list) for i in range(input_length): for j in range(i + 1): ...
-
列表理解: my_new_list = [key for key, value in my_list] 或者只是首先生成一个键列表: my_new_list = sorted(index_dict, key=index_dict.get, reverse=True) List comprehension: my_new_list = [key for key, value in my_list] Or just produce a list of keys in the first place: my ...
-
如何在Python列表中删除子列表项子集的重复项?(How to remove duplicates, by sublist item subset, in a list of lists in Python?)[2021-06-14]
解 您可以使用集来完成此任务: arr = [[2, 3, 5], [3, 3, 1], [2, 3, 8]] used = set() [used.add(tuple(x[:2])) or x for x in arr if tuple(x[:2]) not in used] 回报 [[2, 3, 5], [3, 3, 1]] 笔记 仅在未used任何子列表的前两个元素时才评估第一个表达式。 查看列表推导的文档以获取更多信息。 知道set.add总是返回None 。 所以used.add(tuple ... -
要将第一个元素捕获到变量中,可以使用列表推导,如: 码: data = { 'ID': [[310.5, 1.1612828], [310.0, 15.0], [310.0, 2.9755309], [309.5, 30.0]] } variable = [x[0] for x in data['ID']] print(variable) 结果: [310.5, 310.0, 310.0, 309.5] To capture ...
-
要使编号连续,即使列表中有空白项目,只需使用带有第一个参数None filter来消除任何错误: for sindex, sefer in enumerate(haaros_seforim): for hindex, haarah in enumerate(sefer): for pindex, paragraph in enumerate(filter(None, haarah)): print "INDEX\/ "+str(sindex)+" "+str( ...