首页
\
问答
\
jQuery在每个单选按钮或复选框旁添加空标签标签(jQuery add empty label tags next to every radio button or checkbox)
jQuery在每个单选按钮或复选框旁添加空标签标签(jQuery add empty label tags next to every radio button or checkbox)
我需要一个简单的jQuery代码,在每个单选按钮或复选框旁边添加一个空标签标签
例如:
$('input[type="radio"]').next().add("<label for="radio"></label>"); $('input[type="checkbox"]').next().add("<label for="checkbox"></label>");
我怎样才能做到这一点?
谢谢。
I need a simple jQuery code that will add an empty label tag next to every radio button or checkbox
So for example:
$('input[type="radio"]').next().add("<label for="radio"></label>"); $('input[type="checkbox"]').next().add("<label for="checkbox"></label>");
How can I accomplish this?
Thanks.
原文:https://stackoverflow.com/questions/8530194
更新时间:2022-06-01 17:06
最满意答案
range(1, n+1)
不被视为重复,但我可以看出,如果您要将1
更改为另一个数字,这可能会变成一件麻烦事。这消除了使用生成器的复制:
for _ in (number+1 for number in range(5)): print(_)
range(1, n+1)
is not considered duplication, but I can see that this might become a hassle if you were going to change1
to another number.This removes the duplication using a generator:
for _ in (number+1 for number in range(5)): print(_)
相关问答
更多-
Pythonic方式遍历除了换行符以外的文件(Pythonic way to iterate through a file on something other than newlines)[2024-02-11]
迭代迭代,你不需要存储所有行: for line in f: for lines in line.split(","): Iterate over the split as you go then you don't need to store all the lines: for line in f: for lines in line.split(","): -
你可以用math.copysign和abs函数来编写它: In [30]: from math import copysign In [31]: joyx = copysign(100, joyx) if abs(joyx) > 50 else 0 例: In [32]: joyx = lambda x: copysign(100, x) if abs(x) > 50 else 0 In [33]: joyx(51), joyx(-51), joyx(50), joyx(-50), joyx(0) O ...
-
range(1, n+1)不被视为重复,但我可以看出,如果您要将1更改为另一个数字,这可能会变成一件麻烦事。 这消除了使用生成器的复制: for _ in (number+1 for number in range(5)): print(_) range(1, n+1) is not considered duplication, but I can see that this might become a hassle if you were going to change 1 to anoth ...
-
如果someValue是不可变的,则可以使用乘法: someList += [someValue] * someNumber 这会创建对同一someValue对象的 someNumber引用。 这意味着如果someValue是一个可变对象,您将看到该对象的更改反映在所有这些引用中。 因此,对于可变类型,通常使用列表推导来确保创建新对象。 要扩展列表,而不是+=您还可以将list.extend()与生成器表达式一起使用: someList.extend(['extra', 'list', 'elements ...
-
使用DateTime模块。 这是一个简单的例子,它列出了前十天: use 5.012; use warnings; use DateTime; my $end = DateTime->now; my $day = $end->clone->subtract( days => 10 ); # ten days ago while ($day < $end) { say $day; $day->add( days => 1 ); # move along to next day } ...
-
Pythonic方法迭代字典中的列表并行作为一个字典(Pythonic way to iterate over lists inside a dict in parallel AS a dict)[2023-08-08]
您可以直接使用带有dict.values zip 例如: packed = { 'names': ['a', 'b', 'c', 'd'], 'values': ['A', 'B', 'C', 'D'] } keysValue = packed.keys() for pack in zip(*packed.values()): print( dict(zip(keysValue, pack)) ) 输出: {'values': 'A', 'names': 'a'} {'valu ... -
您可以使用最小和最大功能: result = min(max_value, max(min_value, result)) You can use the min and max functions: result = min(max_value, max(min_value, result))
-
是否有Pythonic方法来迭代“扩展”源列表?(Is there a Pythonic way to iterate over an “expanded” source list?)[2023-08-17]
您可以使用多级生成器: src = {"a": 1, "aBar": 2, "b": 3, "bBar": 4} d = {key: src[key] for item in 'ab' for key in (item, item+'Bar')} You could use a multi-level generator: src = {"a": 1, "aBar": 2, "b": 3, "bBar": 4} d = {key: src[key] for item in 'ab' for key in ... -
for i in range(len(array)): 绝对不是迭代数组的Python-ic方式。 这是VisualBasic思维,你应该从中解放自己。 如果要迭代数组,只需按如下方式迭代: array = ['Groceries', 'Restaurant', 'Groceries', 'Misc', 'Bills'] for eachItem in array: ... 你在循环中做什么取决于你。 如果你想计算清单中的杂货,那么你可以这样做: array = ['Groceries', 'Re ...
-
我喜欢Pavel的答案,但它应该是n-1而不是n: import operator end = 1000000 N = (1, 10, 100, 1000, 10000, 100000, 1000000) concatenated_numbers_str = ''.join([str(x) for x in range(1, end + 1)]) print reduce(operator.mul, [int(concatenated_numbers_str[n-1]) for n in N], 1) I ...