[英]jQuery: How to check if after input there is a label
How do I check if label tag exist after input tag? 如何在输入标签后检查标签标签是否存在?
I have this code 我有这个代码
$j(document).ready(function () {
$j('input[type="checkbox"],input[type="radio"]').each(function () {
});
});
I want to check immediately after input[type:checkbox]
and input[tyoe:radio]
if there is label tag. 我想在
input[type:checkbox]
后立即检查,如果有标签标签则input[tyoe:radio]
。
If yes then do nothing, if no then add an empty label tag <label></label>
如果是,则不执行任何操作,否则添加空标签标签
<label></label>
Anyone know how? 谁知道怎么样?
You can use jQuery next() to see if next element is label. 您可以使用jQuery next()来查看下一个元素是否为label。 You will get length = 0 if there is not label.
如果没有标签,你将得到长度= 0。 Once you know if you have label next to input element you can use after() to insert element after the current element.
一旦知道输入元素旁边是否有标签,就可以使用after()在当前元素之后插入元素。
if(!$j(this).next('label').length)
$j(this).after('<label></label>');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.