如何在 2 个跨度之间添加一个跨度?
在我的页面上,我有多个具有指定类的 div,其中有 2 个 span 元素。我想检查第二个元素是否具有特定的类,在两个跨度之间添加新的跨度对象。
var allrtSp = $(".rtSp");
for (i = 0; i < allrtSp.length; i++) {
var cls= $(allrtSp[i]).next().attr('class');
var newSpan;
if (cls != 'rtMinus' && cls != 'rtPlus')
{
$(allrtSp[i]).add('<span class="rtNoChild"></span>');
}
}
我使用了上面的代码,但这不起作用。
On my page, I have multiple div with specified class which have 2 span elements. I want to check if the second element has a particular class, add new span object between the 2 span.
var allrtSp = $(".rtSp");
for (i = 0; i < allrtSp.length; i++) {
var cls= $(allrtSp[i]).next().attr('class');
var newSpan;
if (cls != 'rtMinus' && cls != 'rtPlus')
{
$(allrtSp[i]).add('<span class="rtNoChild"></span>');
}
}
I used the above code, but this is not working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您不应该使用
您拥有的代码将添加一个新的跨度作为 allrtSp[i] 的子级,而不是在它和下一个跨度之间添加。
Shouldn't you be using
The code you have will add a new span as a child of allrtSp[i] as opposed to between it and the next span.
试试这个
Try this
检查此代码:-
Check with this code:-
我能想到的最简洁的:
对于以下 HTML
将产生
Most concise I can think of:
for the following HTML
will produce