javascript 如何更改锚标签内的文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18014596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to change text inside anchor tag
提问by iJade
How to change the text 'save' to 'edit' in this html code using jquery
如何使用 jquery 在此 html 代码中将文本“保存”更改为“编辑”
<a id="personalSave" href="#" class="SaveText">
<span class="FloatLeft">‹</span>
save
<span class="FloatRight">›</span>
</a>
i tried changing the text(savebetween the spans ) using
我尝试使用更改文本(在跨度之间保存)
$('#personalSave').innerText = "edit";
but its not working..
但它不工作..
回答by iJade
This is what worked for me
这对我有用
$('#personalSave').text('edit');
回答by Abhitalks
Wrap your text also in a span:
将您的文本也包裹在一个跨度中:
<a id="personalSave" href="#" class="SaveText">
<span class="FloatLeft">‹</span>
<span class='txt'>save</span>
<span class="FloatRight">›</span>
</a>
Now you can select it:
现在您可以选择它:
$('#personalSave .txt').text("edit");
回答by Matthijs
This should work but it's probably not the best way to do it:
这应该有效,但它可能不是最好的方法:
$("#personalSave").text($("#personalSave").text().replace("save", "edit"));
Better wrap the text in a span and change that.
最好将文本包裹在一个跨度中并进行更改。