.each() 问题,jquery
我正在尝试获取 内的数字,我正在使用
.each()
查找所有 span
但具有获取其中的数字时出现问题。我想将跨度中的数字附加到图像名称,但没有运气?
代码:
var _td = $("td.tri-img span");
$.each(_td, function(i, val){
$(val).html();
console.log(val);
var _img = $('.wrap-graph.relative img');
var _img_src = 'img/triangle' + val + '.png';
_img.attr('src', _img_src);
});
HTML:
<td class="tri-img"><img class="one"src="" alt="" ><span>11</span></td>
<td class="tri-img"><img class="two" src="" alt="" ><span>33</span></td>
<td class="tri-img"><img class="three" src="" alt="" ><span>44</span></td>
<td class="tri-img"><img class="four" src="" alt="" ><span>66</span></td>
I am trying to get the number inside of a <span>
I am using .each()
to find all the span
s but having problems getting the number inside of it. I would like to attach the number in the span to the image name, but no luck??
Code:
var _td = $("td.tri-img span");
$.each(_td, function(i, val){
$(val).html();
console.log(val);
var _img = $('.wrap-graph.relative img');
var _img_src = 'img/triangle' + val + '.png';
_img.attr('src', _img_src);
});
HTML:
<td class="tri-img"><img class="one"src="" alt="" ><span>11</span></td>
<td class="tri-img"><img class="two" src="" alt="" ><span>33</span></td>
<td class="tri-img"><img class="three" src="" alt="" ><span>44</span></td>
<td class="tri-img"><img class="four" src="" alt="" ><span>66</span></td>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更改
为
Change
to
试试这个:
编辑:如果您想清除文本中的任何非数字,请执行以下操作:
Try this:
EDIT: If you want to clean the text of any non-digits, do this: