jQuery将Value传递到字符串中并使其成为锚点 [英] Jquery Pass Value into string and make it an anchor
问题描述
大师们
如何实现这一目标?
<td>
<span class="label">Queued:</span><span class="data"><a href="link1">134</a></span><br>
<span class="label">Reject:<span class="data"><a href="link2">3434</a></span><br>
<span class="label">Offers:</span><span class="data"><a href="link3">234</a></span><br>
</td>
从这里
<table class="obj">
<tr>
<td>
Queued:134,Reject:3434,Offers:234,link1,link2,link3
</td>
<td>
Queued:134,link1,Reject:3434,link2,Offers:234,link3
</td>
</tr>
</table>
link1,link2,link3的值分别需要进入Queued:134,Reject:3434和Offers:234,单击时应进入链接页面.可能吗??
Value of link1,link2,link3 needs to go into Queued:134,Reject:3434 and Offers:234 respectively and when it is clicked it should take to the linked page. Possible ??
我们将不胜感激?
推荐答案
我以前从未尝试过这样做,因此这可能是实现这一目标的一种非常尴尬的方式,但下面的工作方式可以解决.您遇到的问题是两个TD的格式不同.我的代码的第一部分适用于第一个TD,而我的第二部分的代码适用于第二个TD.
I've never tried to do this before so this could be a really awkward way of achieving this but below works. The problem you have is that the two TDs are formatted differently. The first section of my code works for the first TD and my second section of code works for the second TD.
我可以将两部分代码组合在一起,以便对第一个TD进行编码,而对第二个TD进行编码,但我会让你这样做:)
I could combine the two sections of code to do one for the first TD and the other for the second, but I'll let you do that :)
$('.obj td').each(function(){
fullstring = $(this).text();
splitString = fullstring.split(',');
splitStringLength = splitString.length/2;
for(i=0; i<splitStringLength; i++){
finalString = splitString[i].split(':');
label = '<span class="label">' + finalString[0] + '</span>';
data = '<span class="data"><a href="'+splitString[i+3]+'">'+finalString[1]+'</a></span><br/>';
$('body').append(label + data);
}
});
});
$('.obj td').each(function(){
fullstring = $(this).text();
splitString = fullstring.split(',');
for(i=0; i<splitString.length; i=i+2){
finalString = splitString[i].split(':');
label = '<span class="label">' + finalString[0] + '</span>';
data = '<span class="data"><a href="'+splitString[i+1]+'">'+finalString[1]+'</a></span><br/>';
$('body').append(label + data);
}
});
});
这篇关于jQuery将Value传递到字符串中并使其成为锚点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!