admin管理员组文章数量:1026373
I have a simple question for jQuery...
I have a table with a link like this
<table>
<tr>
<td class="views-field">
<a href="ciao">201105</a>
</td>
</tr>
</table>
Now I would change the link's text from 201105 to 2011-05
(simple add a "-" after the first 4 characters)
I tried substring but don't work... Help me!!
I have a simple question for jQuery...
I have a table with a link like this
<table>
<tr>
<td class="views-field">
<a href="ciao">201105</a>
</td>
</tr>
</table>
Now I would change the link's text from 201105 to 2011-05
(simple add a "-" after the first 4 characters)
I tried substring but don't work... Help me!!
Share Improve this question edited Sep 30, 2011 at 13:35 Matt 75.3k26 gold badges156 silver badges180 bronze badges asked Sep 30, 2011 at 13:13 Fra OreFra Ore 151 silver badge5 bronze badges 2- Can you post the code you tried? It would make pointing out the error easier. – Frédéric Hamidi Commented Sep 30, 2011 at 13:14
- What have you tried? We're happy to help but would rather not do your homework :) – Kerry Jones Commented Sep 30, 2011 at 13:14
3 Answers
Reset to default 5This will translate all td.views-field links:
$('td.views-field a').each(function () {
var oldText = $(this).text();
$(this).text(oldText.substr(0,4) + '-' + oldText.substr(4));
});
$("a").text($("a").text().substring(0,4)+"-"+$("a").text().substring(4,6) );
Try the code below, that should work fine.
var replaceElement = $("td.views-field a").first();
var oldDate = replaceElement.text();
var newDate = oldDate.substring(0, 4) + "-" + oldDate.substring(4,6);
replaceElement.text(newDate);
I have a simple question for jQuery...
I have a table with a link like this
<table>
<tr>
<td class="views-field">
<a href="ciao">201105</a>
</td>
</tr>
</table>
Now I would change the link's text from 201105 to 2011-05
(simple add a "-" after the first 4 characters)
I tried substring but don't work... Help me!!
I have a simple question for jQuery...
I have a table with a link like this
<table>
<tr>
<td class="views-field">
<a href="ciao">201105</a>
</td>
</tr>
</table>
Now I would change the link's text from 201105 to 2011-05
(simple add a "-" after the first 4 characters)
I tried substring but don't work... Help me!!
Share Improve this question edited Sep 30, 2011 at 13:35 Matt 75.3k26 gold badges156 silver badges180 bronze badges asked Sep 30, 2011 at 13:13 Fra OreFra Ore 151 silver badge5 bronze badges 2- Can you post the code you tried? It would make pointing out the error easier. – Frédéric Hamidi Commented Sep 30, 2011 at 13:14
- What have you tried? We're happy to help but would rather not do your homework :) – Kerry Jones Commented Sep 30, 2011 at 13:14
3 Answers
Reset to default 5This will translate all td.views-field links:
$('td.views-field a').each(function () {
var oldText = $(this).text();
$(this).text(oldText.substr(0,4) + '-' + oldText.substr(4));
});
$("a").text($("a").text().substring(0,4)+"-"+$("a").text().substring(4,6) );
Try the code below, that should work fine.
var replaceElement = $("td.views-field a").first();
var oldDate = replaceElement.text();
var newDate = oldDate.substring(0, 4) + "-" + oldDate.substring(4,6);
replaceElement.text(newDate);
本文标签: javascriptjQuery change text in linkStack Overflow
版权声明:本文标题:javascript - jQuery change text in link - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745646733a2161069.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论